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.

14 thoughts on “Create Shortcode for WordPress Page Title

  1. 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

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

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

Leave a Reply

Your email address will not be published.

Enquire Now
Share this
Send this to a friend