我是Wordpress编程和学习的新手.
the_title(); //outputs the title of the page
Run Code Online (Sandbox Code Playgroud)
我想将页面的标题捕获到一个字符串变量中,以便我可以使用strtolower和str_replace函数来操作它.
我使用它的唯一方法是使用输出缓冲.
ob_start();
the_title();
$result = ob_get_clean();
echo str_replace(" ","-",strtolower($result));
/*there has got to be an easier way....
i dont fully understand why */
str_replace(" ","-",strtolower(the_title()));
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Pao*_*ino 10
如果你真正想要的是wp_title函数,它所采用的第二个参数是一个布尔值,它是否应该显示它或返回它.将其传递为false以便将其返回到var,然后您可以执行以下操作:
$mytitle = wp_title(null, false);
Run Code Online (Sandbox Code Playgroud)
否则,您唯一的选择是找到您正在寻找的功能并修改源代码.