How to get page title in wordpress

时光怂恿深爱的人放手 提交于 2020-12-29 05:46:36

问题


Well, I have tried <?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?


回答1:


Try this one, It's may help you

<?php single_post_title(); ?>

Thanks :)




回答2:


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

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

Thanks




回答3:


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

You should have used ID instead to get the title.

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.




回答4:


You can try this

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

Reference




回答5:


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


来源:https://stackoverflow.com/questions/27653694/how-to-get-page-title-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!