【问题标题】:the_title function to return string instead of echo in Wordpressthe_title 函数在 Wordpress 中返回字符串而不是回显
【发布时间】:2022-01-11 08:14:12
【问题描述】:

在 Wordpress 中,如何更改 the_title() 回显标题的函数以返回字符串 $title 代替?

我在尝试:

the_title() -> $title  
the_title() = $title  

【问题讨论】:

标签: php wordpress


【解决方案1】:

两种方式:

使用get_the_title() 函数。它可用于检索帖子标题。它需要一个可选的 Post ID 或 WP_Post 对象作为参数。

$title = get_the_title();

the_title()函数中设置第三个参数$echo为false。默认情况下,the_title() 函数会回显标题。第三个参数可用于设置 echoing 为 false,并返回标题:

$title = the_title('','', false);

【讨论】:

  • 谢谢,帮助:)
猜你喜欢
  • 2013-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
相关资源
最近更新 更多