WPGraphQL 和 Elementor 获取页面或帖子 css 和脚本

问题描述 投票:0回答:2

Elementor 正在 WordPress 页面的头部部分生成页面特定的样式和脚本。有没有办法将它们读取到 GraphQL?

wordpress wordpress-rest-api elementor wp-graphql
2个回答
0
投票

我分两步对 WpBakery pagebuilder 做了同样的事情:

  1. 使用编辑器中的 CSS 在 graphQL 中注册新字段,例如:

     add_action( 'graphql_register_types', function() {
               register_graphql_field( 'Page', 'customCSS', [
                  'type' => 'String',
                  'description' => __( 'Custom CSS from Editor', 'wp-graphql' ),
                  'resolve' => function() {
                 // call your function which return your custom css
                 return $this->addPageCustomCssToGraphql();
                  }
               ] );
             } );
    
  2. 在 Gatsby 页面中请求它们,并使用 Helmet 插件在页面的 HEAD 中显示您的 CSS。


0
投票

你把这个代码放在哪里? IIn主题的功能还是在哪里? 我找不到在哪里注册它来查询

© www.soinside.com 2019 - 2024. All rights reserved.