WPGraphQL和Elementor获取页面或张贴css和脚本



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

我在两个步骤中为WpBakery页面生成器做了同样的操作:

  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。

最新更新