Site logo

Archived topic

How to get Post/Page title using a shortcode?

3 replies · Started by Rishabh on April 21, 2021

Viewing posts 1–4 of 4

So, I added this below code in my functions.php:

function post_title_shortcode(){
    return get_the_title();
}
add_shortcode('post_title','post_title_shortcode');

Then, I went to Generatepress > Elements > Block and added this short code [post_title]

Screenshot: https://ibb.co/0BdSMbS

But still I am not seeing the title on pages/posts, instead I am seeing the [post_title] written in raw text format.

Here's the page link: https://9to5vpn.com/best-vpns-of-2021/

How to solve this?

I just want to get the page/post title using shortcode, php or anything else.

[Edit] Also if possible, please tell me how to get the featured image using shortcode, php etc.

That's Amazing.

I was waiting for this.

This archived topic is closed to new replies.