How to get page title in wordpress
Asked Answered
P

6

21

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?

Philippe answered 26/12, 2014 at 6:39 Comment(1)
Try global $post; echo $post->post_titleCoady
A
36

Try this one, It's may help you

<?php single_post_title(); ?>

Thanks :)

Ascogonium answered 9/10, 2017 at 20:24 Comment(2)
In my case, I was using the_title() on index.php resulting in the most recent post title being the page title instead of the page title. Your solution resolves this.Outgrowth
How to get the parent element for nested page liks parent_page => sub_page I want to get this parent_page/sub_pageShearer
P
17

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

Pettitoes answered 26/12, 2014 at 12:53 Comment(0)
S
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();

?>
Stereotypy answered 22/4, 2022 at 0:43 Comment(0)
E
4

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.

Evident answered 26/12, 2014 at 6:43 Comment(0)
D
0

You can try this

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

Reference

Danell answered 26/12, 2014 at 6:47 Comment(0)
M
0
<?php
  $page = get_page_by_title( 'About Us' );
 echo get_the_title($page->ID)
?>
Mckenziemckeon answered 26/12, 2014 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.