- This topic has 17 replies, 3 voices, and was last updated 2 years, 11 months ago by David.
-
AuthorPosts
-
May 5, 2021 at 11:06 pm #1766729Yael
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
May 5, 2021 at 11:57 pm #1766786ElvinStaffCustomer SupportHi 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.
May 6, 2021 at 9:14 am #1767754YaelThanks 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.
May 6, 2021 at 4:13 pm #1768144ElvinStaffCustomer SupportWhere 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).
May 6, 2021 at 8:08 pm #1768250YaelI 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
May 6, 2021 at 9:39 pm #1768303ElvinStaffCustomer SupportYou can run shortcodes on the copyright bar if you want it exactly on that place.
Example: – https://share.getcloudapp.com/jkuLjwwZ
May 6, 2021 at 10:18 pm #1768333YaelIt’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
May 6, 2021 at 11:12 pm #1768365ElvinStaffCustomer SupportSince you’re using Tom’s snippet, you should be using
[page_title]
.May 6, 2021 at 11:26 pm #1768379Yaelthat shortcode does not work either. All it does is show [page_title] in the footer, not the site’s title.
Nevermind on this.
May 6, 2021 at 11:42 pm #1768400ElvinStaffCustomer SupportIf 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).
May 6, 2021 at 11:52 pm #1768413YaelAs 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.
May 6, 2021 at 11:59 pm #1768417YaelI 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?
May 7, 2021 at 3:46 am #1768684DavidStaffCustomer SupportHi 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.
May 7, 2021 at 4:05 am #1768709YaelThank 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.
May 7, 2021 at 4:06 am #1768711Yaelp.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
-
AuthorPosts
- You must be logged in to reply to this topic.