PHP WordPress 主题 if/else 失败
我正在开发一个可以普遍用于我的网站的标题。不幸的是,这还包括对 WordPress 功能的大量条件检查,因此我最终得到了正确的标题数据。我有一段代码,用于检查为 WordPress 页面提供标题的函数是否存在。如果是,它就会检查该函数是否返回任何内容。如果没有,它会打印默认标题。否则,它会打印标题并向其附加标准标题。我的问题是它似乎打印标题,然后附加默认标题。因此,它不是打印:“pageTitle-append”,而是打印“pageTitleStandardTitle-append”。这是我的代码:
if(function_exists('wp_title')):
if(wp_title()):
wp_title();
echo ' - Standard Appended Title';
else:
echo 'Blog - Standard Appended Title';
endif;
else:
echo $title.' - Standard Appended Title';
endif;
I was working on a header that could be used universally for my site. Unfortunately, this also includes a lot of conditional checking for WordPress functions, so that I end up with the correct data for headings. I have a piece of code that checks to see if the function that provides a title for WordPress pages exists. If it does, it then checks to see if that function returns anything. If it doesn't, it prints a default title. Otherwise, it prints the title and appends a standard title to it. My problem is that it seems to print the title, and then appends the default title. So instead of printing: "pageTitle-append" it prints "pageTitleStandardTitle-append". Here's my code:
if(function_exists('wp_title')):
if(wp_title()):
wp_title();
echo ' - Standard Appended Title';
else:
echo 'Blog - Standard Appended Title';
endif;
else:
echo $title.' - Standard Appended Title';
endif;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以做到:
This should do it :