0
你好计算器,WordPress二十十二,如何输出wp_title的前两个单词?
我使用wp_title输出页面的标题,但有些标题太长。
任何人都可以解释我如何编写该函数只返回标题的前2个单词?
图为例:谢谢。
<?php wp_title(''); ?>
你好计算器,WordPress二十十二,如何输出wp_title的前两个单词?
我使用wp_title输出页面的标题,但有些标题太长。
任何人都可以解释我如何编写该函数只返回标题的前2个单词?
图为例:谢谢。
<?php wp_title(''); ?>
//use this code in functions.php file
add_filter('wp_title', set_page_title($message));
function set_page_title($message) {
$message = explode(' ', $message, 2);
$message = implode(' ', $message);
//Here I can echo the result and see that it's actually triggered
return $message;
}
它不会工作,我相信我需要使用SUBSTR,谢谢寿 –