php - 使用帖子 ID 获取 wp_title 但 Yoast SEO 会覆盖输出
问题描述
所以我有点失去理智,似乎无法弄清楚我遇到的这个问题,所以我尝试了所有可能的方法来使用帖子 ID 获取帖子的“标题”?听起来很容易对吧?
好吧,问题是标签上的帖子标题是:
Post_title (Separator) Blogname : My Lovely Post - BlogName
我使用了核心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);
效果很好,我得到了回声响应。
问题:我没有得到特定帖子的帖子(分隔符)博客名称,而是在回声上得到了 Yoast SEO 覆盖响应。有没有一种方法可以让我得到 Yoast 的回复并使用帖子标题(分隔符)博客名称?
我想要的只是获得带有标签的帖子 ID 标题名称,因此带有分隔符的那个,但似乎 Yoast SEO 接管了,所以我无法准确地弄清楚那部分。
解决方案
推荐阅读
- wordpress - 在 WooCommerce 管理订单页面中保存多个选择选项可编辑字段
- c++ - 使用 pqxx 在 postgresql 中存储 std::vector 并从数据库中检索它。
- batch-file - IF "71" GTR "7000" 为真
- excel - Multiple If Else in Excel
- amazon-web-services - 使用 Cloudwatch 监控 AWS EC2 实例的 JVM 使用情况
- c++ - Handle flash window event
- amazon-ec2 - 当 Pod 数量很高时,Kubernetes 仪表板没有响应
- dataset - 如何获得xarray数据集中的最大间隙时间
- java - StringBuilder with some text in red overriding toString in Java
- optimization - 使用牛顿法优化成本函数