WordPress交换变量?
我正在创建一个函数来处理页面、帖子、主页等的标题。。然而,我遇到了一个问题 以下是Functions.php中的代码:WordPress交换变量?,wordpress,Wordpress,我正在创建一个函数来处理页面、帖子、主页等的标题。。然而,我遇到了一个问题 以下是Functions.php中的代码: function theTitle() { $siteName = bloginfo('name'); $sitePage = get_the_title(); if (is_home()) { echo $siteName; } if (is_page()) { echo "(". $sitePage . ")
function theTitle() {
$siteName = bloginfo('name');
$sitePage = get_the_title();
if (is_home()) {
echo $siteName;
}
if (is_page()) {
echo "(". $sitePage . ") » " . $siteName;
}
}
当您在主页上时,标题为:
<title>This is the title specified in settings</title>
<title>This is the title specified in settings(About Us) » </title>
这是在设置中指定的标题
但是,当您转到单个页面时,标题是:
<title>This is the title specified in settings</title>
<title>This is the title specified in settings(About Us) » </title>
这是设置(关于我们)中指定的标题»;
如您所见,它首先输出$siteName,而不是将其添加到末尾。以前有人见过这个吗?你知道为什么吗
感谢bloginfo()
回显get\u bloginfo()
的返回值,因此请使用get\u bloginfo()