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.
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.
Too many Thanks
Thank you and you are welcome.
Nice info! Thanks
This just saved me $800.00.
Thanks,
Are you kidding? If it is real we are too glad that we helped you.
i need this! thanks, what about if the tittle had had to be linked to the post?
You are welcome. Yes, the above short-code works in posts as well.
Is is possible to create a shortcode for the parent page title?
website is well
site and post is good
Thanks a lot!
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
I founded :
add_shortcode( ‘px_post_title’, ‘px_post_title’ );
function px_post_title() {
$post_title = get_the_title($post = 514);
return $post_title;
}
Hi Pascal, thank you for sharing the code that displays a specific post title. We will update this in the article.
Hi, is it also possible to include the shortcode into a php template file somehow? Thanks!
Very useful code snippet, does exactly what it should. Please create and post more simple useful code snippets like this one, thanks.
Amazing it works! You saved me much time. Appreciated!