Create Shortcode for WordPress Page Title

We come across situations in which we need to show current WordPress page title or include WordPress page / post title in the content. A shortcode can be put to use in such cases. Here is a quick example of PHP code needed to create a short code for WordPress Page Title. Add the below code to functions.php file of your theme.
function page_title_sc( ){
   return get_the_title();
}
add_shortcode( 'page_title', 'page_title_sc' );
This will create a short code called
[page_title]
Use this shortcode [page_title] in you wordpress content, it returns the page / post title. Contribute for the ultimate list of WordPress snippets

Do you have anymore complicated WordPress related issues or looking for custom web design or development. We are a web design & development company in Chennai, would love to provide solutions for your issues.

17 Comments:
February 19, 2018

Too many Thanks

March 30, 2018

Thank you and you are welcome.

December 8, 2018

Nice info! Thanks

January 24, 2019

This just saved me $800.00.

Thanks,

January 31, 2019

Are you kidding? If it is real we are too glad that we helped you.

February 15, 2019

i need this! thanks, what about if the tittle had had to be linked to the post?

February 18, 2019

You are welcome. Yes, the above short-code works in posts as well.

February 28, 2019

Is is possible to create a shortcode for the parent page title?

May 15, 2019

website is well

site and post is good

June 20, 2019

Thanks a lot!

June 3, 2020

Hello and thank you for this code. i’m searching for a shortcode like [post_title post_id=3] to display in a page the title of a the post number 3

June 3, 2020

I founded :
add_shortcode( ‘px_post_title’, ‘px_post_title’ );
function px_post_title() {
$post_title = get_the_title($post = 514);
return $post_title;
}

June 11, 2020

Hi Pascal, thank you for sharing the code that displays a specific post title. We will update this in the article.

August 6, 2020

Hi, is it also possible to include the shortcode into a php template file somehow? Thanks!

September 6, 2021

Very useful code snippet, does exactly what it should. Please create and post more simple useful code snippets like this one, thanks.

June 16, 2022

Amazing it works! You saved me much time. Appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *

See More Blogs

Contact us

Partner with Us for Comprehensive IT Solutions

We’re happy to answer any questions you may have and help you determine IT solutions to shape up your idea or streamline your processes.

Your benefits:
What happens next?
1

We Schedule a call at your convenience 

2

We do a discovery and consulting meeting 

3

We prepare a proposal 

Schedule a Free Consultation