【问题标题】:how to make yoast seo read text from custom fields in custom post type如何让 yoast seo 从自定义帖子类型的自定义字段中读取文本
【发布时间】:2023-01-13 01:53:35
【问题描述】:

我有一个 WordPress 网站,在该网站中,我使用的主题定义了一个名为 Recipe 的自定义帖子,该帖子用于为 Food Recipe 添加数据,例如每个词干的步骤和描述,并在友好的 UI/UX 中显示

目前,我正在尝试增强我的食物食谱的搜索引擎优化,为此我正在使用 Yoast 搜索引擎优化

Text length: The text contains 0 words. This is far below the recommended minimum of 300 words. Add more content.

它不会从我的自定义帖子字段中读取数据,我已经搜索了很多并尝试了很多插件,但我所有的尝试都失败了

有什么方法可以让 Yoast SEO 分析从我的自定义字段中读取文本?

【问题讨论】:

    标签: wordpress seo yoast


    【解决方案1】:

    要使 Yoast SEO 从自定义帖子类型的自定义字段中读取文本,您需要将一些代码添加到 WordPress 主题的 functions.php 文件中。具体来说,您需要使用 wpseo_pre_analysis_post_content 过滤器来修改 Yoast SEO 用于分析的帖子内容。

    以下是您如何使用此过滤器在帖子内容中包含名为“seo_description”的自定义字段的值的示例:

    function add_custom_field_to_content( $content ) {
        global $post;
        if ( get_post_type( $post->ID ) == 'custom_post_type' ) {
            $custom_content = get_post_meta( $post->ID, 'seo_description', true );
            $content = $custom_content . ' ' . $content;
        }
        return $content;
    }
    add_filter( 'wpseo_pre_analysis_post_content', 'add_custom_field_to_content' );
    

    此代码首先检查以确保当前帖子属于您要定位的自定义帖子类型,然后使用 get_post_meta() 函数检索“seo_description”自定义字段的值。然后它将自定义字段值与原始帖子内容连接起来,并返回修改后的内容供 Yoast SEO 分析。

    请记住,这只是一个示例,您需要自定义代码以匹配您的自定义帖子类型、自定义字段名称和任何其他特定要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多