Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress标题PHP Wordwrap_Php_Wordpress_Word Wrap - Fatal编程技术网

Wordpress标题PHP Wordwrap

Wordpress标题PHP Wordwrap,php,wordpress,word-wrap,Php,Wordpress,Word Wrap,我希望php计算我的Wordpress帖子标题中的字符数,如果超过50个,请在第50个字符所在的单词前插入一个分隔符 对于这一点,我认为是最好的选择 我在模板中使用了下面的代码,它只是回显标题而没有插入分隔符。有什么想法吗 <?php $text = the_title_attribute(); $newtext = wordwrap($text, 50, "<br />\n"); echo $newtext; ?> 解决了这个问题-我需要使用get_the_title

我希望php计算我的Wordpress帖子标题中的字符数,如果超过50个,请在第50个字符所在的单词前插入一个分隔符

对于这一点,我认为是最好的选择

我在模板中使用了下面的代码,它只是回显标题而没有插入分隔符。有什么想法吗

<?php
$text = the_title_attribute();
$newtext = wordwrap($text, 50, "<br />\n");
echo $newtext;
?>

解决了这个问题-我需要使用get_the_title();相反

工作代码:

<?php
$text = get_the_title();
$newtext = wordwrap($text, 50, "<br />\n");
echo $newtext;
?>


任何在WP Codex中查找函数的人都知道这一点,我认为您没有这样做。WP的函数会回显值或返回值,因为您使用了错误的函数。请看:是的,我只是选错了一个。要获得摘要,您可以使用
the_extract()