Archived topic
How to get Post/Page title using a shortcode?
3 replies · Started by Rishabh on April 21, 2021
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.
Hi there,
try GPP 2.0 - its in the final release candidate stage and will go live next week:
https://generatepress.com/introducing-the-gp-theme-builder/
No need for shortcodes - just add the GenerateBlocks plugin, use a GB Headline Block and set the Dynamic Text type to Post Title.
That's Amazing.
I was waiting for this.
You may find our YT Channel useful: https://www.youtube.com/channel/UCoHk-JZFs1N-iI2DQlIKVnA
Glad to be of help!