Site logo

[Resolved] How to get Post/Page title using a shortcode?

Home Forums Support [Resolved] How to get Post/Page title using a shortcode?

Home Forums Support How to get Post/Page title using a shortcode?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1744057
    Rishabh

    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.

    #1744366
    David
    Staff
    Customer Support

    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.

    #1745206
    Rishabh

    That’s Amazing.

    I was waiting for this.

    #1745559
    David
    Staff
    Customer Support

    You may find our YT Channel useful: https://www.youtube.com/channel/UCoHk-JZFs1N-iI2DQlIKVnA

    Glad to be of help!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.