WordPress wp_title 索引页上为空白
我是 WordPress 新手,刚刚安装了 3.3.1 版本。
我对这个问题做了一些谷歌搜索,找到了一些答案,但它们与 2.7 版本相关,并且已有 2-3 年历史。
基本上,wp_title
函数在每个页面上都运行良好,除了我的主页,它返回空白并且我没有任何标题。我可以硬编码标题,但我不想这样做。
有罪的代码行:
<title><?php wp_title ( '| So Fresh n\' So Clean', true,'right' ); ?></title>
我找不到任何关于 3.3.1 中发生的这个问题的信息,所以很明显我做错了什么。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
以下是我从 Codex 中读到的内容:
因此,请使用
is_front_page()
获取主页上的标题,如上面代码中建议的方式。Here's is what I read from Codex:
So use
is_front_page()
to get the title on homepage, the way it is suggested in above code.更新
对于 WordPress 版本 (>= 4.4)
试试这个
在functions.php 中执行此操作并从 head 中删除“title”标签...
Update
for WordPress versions (>= 4.4)
Try this
Do this in functions.php and remove 'title' tag from head...
但如果您使用静态主页,则代码如下:
But if you use a static home page, this is the code:
根据 Amna 的回答,我想出了以下代码,该代码应该在有页面标题时显示页面标题,后跟网站名称。
帖子/页面输出:“页面标题 - 站点名称”
主页输出:“站点名称”
显然,也可以将其交换为首先显示站点名称。
帖子/页面输出:“站点名称 - 页面标题”
主页输出:“站点名称”
这也可以与条件结合使用,以在查看主页时显示站点描述。
帖子/页面输出:“站点名称 - 页面标题”
主页输出:“站点名称 - 站点描述”
Working off of Amna's answer, I came up with the following code which should display the page title when there is one, followed by the site name.
Post/Page Outputs: "The Page Title - Site Name"
Home Page Outputs: "Site Name"
Obviously, this can also be swapped to display the site name first.
Post/Page Outputs: "Site Name - The Page Title"
Home Page Outputs: "Site Name"
This can also be combined with a conditional to display the site description when viewing the home page.
Post/Page Outputs: "Site Name - The Page Title"
Home Page Outputs: "Site Name - The Site Description"
对于在 wordpress wp_title 上的 google 搜索为空,这是第一个结果。所以我想我可以分享最优雅的解决方案。
在functions.php中添加wp_title过滤器。
For google search on wordpress wp_title empty this is the first result. So I thought that I might share the most elegant solution for this.
In functions.php add a filter for wp_title.
Codex 的新 hack 如下:
然后在主题文件的“functions.php”中:
The new hack from Codex is as follows:
Then in your "functions.php" from theme file :
我使用这个,它从未失败过:
请注意,其中有您可能想要更改的翻译域。
I use this one and it never failed:
Note that there are translation domains in it that you might want to change.
我的“迷雾湖”主题 2 美分,该主题在主页上没有标题,并且在所有其他页面上添加了错误的标题。
只需从 header.php 中删除以下行即可解决问题,因为 Wordpress 现在自行注入标签:
我查阅了以下页面 – https://make.wordpress.org/themes/2015/08/25/title-tag-support-now-required/
My 2 cents for "misty lake" theme which had no title on home page and added incorrect title on all other pages.
Just removing the following line from header.php solves the issue, since Wordpress now injects the tag by itself:
I consulted the following page – https://make.wordpress.org/themes/2015/08/25/title-tag-support-now-required/
不需要。只需添加
代码位于 header.php 末尾,
祝你好运。
no need. Just add the
<? Php wp_head ();?>
Code at the end of the header.phpgood luck.
我在我的 WordPress 网站中使用此方法
I use this method in my WordPress site
对话晚了...
但是如果您想使用用于静态首页的页面的实际标题,您可以使用以下内容:
尽管在 wp_title() 的实际源代码中,有以下内容,特别是在静态首页禁用此功能:
我怀疑这样做是有充分理由的。因此,请谨慎行事。
Late to the conversation...
But if you want to use the actual title of the page that you are using for the static front page, you can use the following:
Although, in the actual source for wp_title(), there is the following, specificaly disabling this for the static front page:
I suspect there is good reason for this. So, proceed with caution.
您还可以在标题标签中添加类似的内容:
You could also put something like this inside your title tag: