微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用帖子 ID 获取 wp_title 但 Yoast SEO 覆盖输出

如何解决使用帖子 ID 获取 wp_title 但 Yoast SEO 覆盖输出

所以我有点失去理智,似乎无法弄清楚我遇到的这个问题,所以我尝试了所有可能的方法来使用帖子 ID 获取帖子的“标题”?听起来很简单吧?

好吧,问题是标签上的帖子标题是:
Post_title(分隔符)博客名称我可爱的帖子 - 博客名称

我使用了核心 wp_title 函数并对其进行了调整,并传入了一个 post 参数,其工作方式如下所示:

/**
     * Get the office post title
     *
     * @param string $post_id
     * @param string $sep
     * @param string $seplocation
     * @return mixed|string|void
     */
    function office_wp_title(string $post_id = '',string $sep = '»',string $seplocation = '') {

        // Check if the post ID exists.
        if (!$post_id) {
            return '';
        }

        // Grab the post
        $post = get_post($post_id);

        // Check if the post is not an object and/or doesn't have a post title
        if (!is_object($post) || !isset($post->post_title)) {
            return '';
        }

        // Use native wp_title separator
        $t_sep = '%WP_TITLE_SEP%';

        // Set the single post filter title as the post title
        // Returns: Opinion e Imagen
        $title = apply_filters('single_post_title',$post->post_title,$post);

        // Keep the native prefix checks
        $prefix = '';
        if (!empty($title)) {
            $prefix = " $sep ";
        }

        // Keep the native title array
        $title_array = apply_filters('wp_title_parts',explode( $t_sep,$title));

        // Keep the native separator location
        if ('right' == $seplocation) {
            $title_array = array_reverse($title_array);
            $title = implode(" $sep ",$title_array) . $prefix;
        } else {
            $title = $prefix . implode(" $sep ",$title_array);
        }

        // Keep the native filters and return title.
        $title = apply_filters('wp_title',$title,$sep,$seplocation);
        echo $title;
    }

然后,我在我的文件调用它,例如 $office_obj->office_wp_title($office->ID); 效果很好,我得到了回声响应。

问题: 我没有获得特定帖子的帖子(分隔符)BlogName,而是在回声中收到 Yoast SEO 覆盖响应。有没有办法让我得到 Yoast 的回复并回到帖子标题(分隔符)博客名称

我想要的只是获取 Post ID 标签标题名称,所以是带有分隔符的名称,但似乎 Yoast SEO 接管了,所以我无法准确地弄清楚那部分。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。