[Resolved] Shortcode for Site Title

Home Forums Support [Resolved] Shortcode for Site Title

Home Forums Support Shortcode for Site Title

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1766729
    Yael

    I want to use shortcode to add Site Title to the footer because this is a multilingual site.

    Tom shared a code snippet for pulling in page title here:

    https://generatepress.com/forums/topic/add-page-title-in-page-header/#post-245321

    but how to pull in site title via shortcode?

    Thank you. Yael

    #1766786
    Elvin
    Staff
    Customer Support

    Hi there,

    The shortcode Tom provided there uses [page_title]

    You can figure out what shortcode is being used by checking the code.

    Example: add_shortcode( 'page_title','tu_page_title_shortcode' );

    After the add_shortcode( you’ll see 'page_title' which is the tag to be used to call the shortcode.

    Calling the shortcode is basically [ + shortcode tag + ].

    Example: for add_shortcode( 'display_title','tu_page_title_shortcode' );

    You can call this with [display_title].

    Now, as for actually using the shortcode on footer, add a text widget on the footer widget area you want it to be placed in and place the shortcode to the text widget area.

    #1767754
    Yael

    Thanks for this however I want to display the site title in the footer, not in a footer widget area so I gather there’s no way to pull in the site tile into Customize . Layout . Footer . Copyright.

    Is that right?

    It doesn’t really make sense to add site title to a widget area, especially since I am not using any widgets. Site title and copyright goes on the footer.

    #1768144
    Elvin
    Staff
    Customer Support

    Where exactly on the footer bar do you want the title to be placed? Can you show an image pointing us to it?

    You can use the shortcode on a Block Element or a Hook Element and hook it into the footer if you don’t want to add it through the footer widget areas (footer 1-5 or footer bar widget).

    #1768250
    Yael

    I want to add it to the footer bar

    Layout > Footer > Copyright.

    I am not using footer widgets nor have I replaced the default footer with a block or hook element. I just wanted to use the default footer found under copyright

    #1768303
    Elvin
    Staff
    Customer Support

    You can run shortcodes on the copyright bar if you want it exactly on that place.

    Example: – https://share.getcloudapp.com/jkuLjwwZ

    #1768333
    Yael

    It’s not working; the only thing that shows when adding shortcode to copyright is the [short_code]

    Here is a very short screencast showing you what I’ve done and what is happening

    https://share.sendspark.com/view/j1h0dqv7j7pw25ha

    #1768365
    Elvin
    Staff
    Customer Support

    Since you’re using Tom’s snippet, you should be using [page_title].

    #1768379
    Yael

    that shortcode does not work either. All it does is show [page_title] in the footer, not the site’s title.

    Nevermind on this.

    #1768400
    Elvin
    Staff
    Customer Support

    If a shortcode isn’t working, it’s likely due to the place you’ve added doesn’t allow shortcode execution or the PHP snippet adding the shortcode is incorrect.

    In your case, the copyright text area allows shortcode so the PHP snippet must’ve got a bit of issue like wrong syntax, or it was added on the wrong place (some users mistakenly add PHP snippets on CSS code areas).

    #1768413
    Yael

    As I showed you in the first screencast, I placed the shortcode you provided in my child theme’s function.php file. I know how to add shortcodes.

    ‘add_shortcode( ‘display_title’,’tu_page_title_shortcode’ );’

    I’ve recorded another screen cast showing that I have placed the code snippet provided correctly but it does not work.

    https://share.sendspark.com/view/h4trxy1pznpnmou0

    #1768417
    Yael

    I now undertand the issue — you didn’t provide the complete code snippet that needs to be added, only the first line. and so I only added the first line! My mistake

    ‘add_shortcode( ‘page_title’,’tu_page_title_shortcode’ );
    function tu_page_title_shortcode()
    {
    return get_the_title();
    }’

    But even after adding the completed code snippet to my child theme’s function.php file (as shown above), it still only shows the shortcode in the footer.

    Will you please confirm the complete code snippet needed in order to pull in the site title using a shortcode?

    #1768684
    David
    Staff
    Customer Support

    Hi there,

    that shortcode should work – unless there is another plugin or function interfering with it.
    However, that shortcode would actually return the Page Title and not the Site Title.

    If you’re happy to carry on trying then remove what your currently have in your functions.php. And add this:

    add_shortcode( 'site_title','db_site_title_shortcode' );
    function db_site_title_shortcode()
    {
        return get_bloginfo( 'name' );
    }

    Then on a draft page can you add this to the content:

    [site_title]

    If the site title displays correctly then we know that the function is working.
    If so try adding the shortcode to the copyright info… as a test – remove all other content from the copyright first.
    Does it then display?

    Regarding screenshot/video uploads – as much as we would like to add an upload directory to the GP forum it would require a huge amount of extra database storage and security layers to manage that.

    #1768709
    Yael

    Thank you, David, that works perfectly 🙂

    Now I guess I’ll just need to add the string translation for footer so I can display in both languages.

    But that code snippet works as expected.

    Thank you so much.

    #1768711
    Yael

    p.s. I was hoping it would pull in site title based on language and settings in Customizer but it only displays site title in English. I think though that I can deal with that with WPML String translations

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