wordpress 如何在wordpress中获取页面标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27653694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:02:53  来源:igfitidea点击:

How to get page title in wordpress

wordpresspage-title

提问by kushalvm

Well, I have tried <?php echo get_the_title('About Us');?>

嗯,我试过了 <?php echo get_the_title('About Us');?>

But the code is not working. I am using wordpress 4.1. This should work but it isn't. Has wordpress updated the functions?

但是代码不起作用。我正在使用 wordpress 4.1。这应该有效,但事实并非如此。wordpress 更新了功能吗?

回答by Mohammad Al-amin

Try this one, It's may help you

试试这个,它可能会帮助你

<?php single_post_title(); ?>

Thanks :)

谢谢 :)

回答by Rahul Vaghela

Try this one,may it's help you

试试这个,可能对你有帮助

<?php echo get_the_title(); ?>

And if you want to get page or post title By id

如果您想通过 id 获取页面或帖子标题

 <?php echo get_the_title(post->$ID); ?> 

Thanks

谢谢

回答by Rohil_PHPBeginner

You are giving wrong parameters to get_title. See the codex.

你给了错误的参数get_title。见codex

You should have used IDinstead to get the title.

您应该使用它ID来获取标题。

So your code would be

所以你的代码将是

 <?php echo get_the_title(13); //where 13 is the ID of the about us page ?>

NOTE:Parameters are optional.

注意:参数是可选的。

回答by Vaibs_Cool

You can try this

你可以试试这个

 <?php echo get_page_by_title( 'About' ); ?>

Reference

参考

回答by Yamu

<?php
  $page = get_page_by_title( 'About Us' );
 echo get_the_title($page->ID)
?>