'How to get page title in wordpress
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?
Solution 1:[1]
Try this one, It's may help you
<?php single_post_title(); ?>
Thanks :)
Solution 2:[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
Solution 3:[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.
Solution 4:[4]
Solution 5:[5]
You could use the_title()
to display the title of the page. You can pass parameters for before and after HTML tags. For morr information, here are the docs:
https://developer.wordpress.org/reference/functions/the_title/
<?php
the_title();
?>
Solution 6:[6]
<?php
$page = get_page_by_title( 'About Us' );
echo get_the_title($page->ID)
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohammad Al-amin |
Solution 2 | Rahul Vaghela |
Solution 3 | Rohil_PHPBeginner |
Solution 4 | Vaibs_Cool |
Solution 5 | JayDev95 |
Solution 6 | Yamu |