Site logo

Archived topic

Shortcode for Site Title

17 replies · Started by Yael on May 5, 2021

Viewing posts 1–15 of 18

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.

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.

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

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

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

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

Nevermind on this.

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

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

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?

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.

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.

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

This archived topic is closed to new replies.