php - 如何使用 Title() 过滤器挂钩来更改页面标题,而不是菜单标题
问题描述
我想使用过滤器挂钩在我的页面标题之前添加图像,但它也会将它们添加到我的菜单标题中。我怎样才能解决这个问题?
function scissorTitle ($title)
{
$scissortitle .= "<img src='*image_link*'>" . $title;
return $scissortitle;
}
add_filter( 'title', 'scissorTitle', 10);
解决方案
过滤器title
有两个参数$title
,$id
您可以使用 $id 更改页面Check docs的唯一特定标题。您的完整代码应如下所示:
function scissorTitle ($title, $id) {
global $post;
if (is_singular() && $post->ID == $id) {
$title = '<img src="image_link">' . $title;
}
return $title;
}
add_filter( 'the_title', 'scissorTitle', 10, 2);
推荐阅读
- c++ - 首先尝试字符串数组不起作用。有什么我不知道的吗?
- python - 用于匹配管道字符内所有数字的 Python 正则表达式
- python - 有没有办法不必在 python 中的数学函数之前编写“math.”?
- c - 在结构上实现排序算法
- ruby - Mac/Xcode - pod install, pod init, pod...所有错误“错误的解释器:没有这样的文件或目录”
- javascript - Vue在数据表中相乘
- core-data - 无法在我的 macbook 上找到我的核心数据文件
- html - 不显示切换。姜戈
- python - Mordecai:无法连接到本地运行的 Elasticsearch 容器
- python - 获得德州扑克获胜概率的有效方法