- This topic has 8 replies, 2 voices, and was last updated 4 years, 10 months ago by David.
-
AuthorPosts
-
May 9, 2019 at 5:08 am #893922Henry
I’d like to insert text BEFORE the “tag” title.
By “tag” I mean the WordPress taxonomy of > ‘Categories’ and ‘Tags’
So, if I create a Tag then GeneratePress just inserts the word that I am using for the tag. If I call the tag “New York” then the page created by GeneratePress just has the title of “New York”.
I would like to add text BEFORE the “New York:
The URL is like this: http://my-site.com/tag/new-york/
This works but only for categories – not for ‘tags’ annoyingly.
Any ideas?
add_filter( 'get_the_archive_title', 'custom_taxonomy_archive_title' ); /** * Remove archive labels. * * @param string $title Current archive title to be displayed. * @return string Modified archive title to be displayed. */ function custom_taxonomy_archive_title( $title ) { if ( is_tax('us_state') ) { $title = single_term_title( 'Conferences In ', false ); } elseif ( is_tax('country') ) { $title = single_term_title( 'Conferences In ', false ); } return $title; }
Thanks!
May 9, 2019 at 6:40 am #894028DavidStaffCustomer SupportHi there,
sorry little confused, so are you looking at the permalink structure for the Tag archive or the single post?
May 9, 2019 at 6:52 am #894169HenryI mean to insert text BEFORE the “tag” title into GeneratePress.
So, when you create a “tag” in WordPress is creates an archive for content associated with that “tag”
If the “tag” is labelled as “Apples” then GeneratePress places that label in this HTML:
<header class="page-header"> <h1 class="page-title">Apples </h1> </header>
I’d like to be able to place text (probably by using a filter) BEFORE the word “Apples”
Thanks and I hope that makes sense!
May 9, 2019 at 8:20 am #894281DavidStaffCustomer SupportYou could use a CSS before pseudo element:
body.tag .page-title:before { content: 'Before: '; }
Each tag has its own body class so you can target them specifially e.g
body.tag-new-york
May 9, 2019 at 5:34 pm #894716HenryThanks, David
That worked great for the onpage main content header section – but – it doesn’t change the
<title>Meta Title Tag</title>
in the header.I really would need that to change for SEO – any ideas on possible workaround for that?
Thanks again.
May 9, 2019 at 5:53 pm #894724HenryIn fact – David, ignore my last point – I can use a SEO Plugin that works great.
As usual – amazing support. Thank You!
May 10, 2019 at 1:31 am #894942DavidStaffCustomer SupportGlad we could be of help
June 6, 2019 at 7:24 pm #922211HenryHi David – in fact, I discovered that the solution you gave (which works) doesn’t actually generate text WITHIN the actual HTML.
So, if you see an example: https://infosec-conferences.com/city/new-york/
You will see that the title: “Cybersecurity Conferences In” < that is NOT in the
<h1 class="page-title">
because it is being entered via the CSS rule you suggested.Whilst it works for the human, I was kinda hoping Google Bot could also see that which seems it can’t so any help/ direction with that would be awesome!
BTW I achieved the above using a functions.php snippets which works great on Custom Post Types & Taxonomy but oddly it didn’t work for Generic WordPress Tags:
add_filter( 'get_the_archive_title', 'custom_taxonomy_archive_title' ); /** * Remove archive labels. * * @param string $title Current archive title to be displayed. * @return string Modified archive title to be displayed. */ function custom_taxonomy_archive_title( $title ) { if ( is_tax('us_state') ) { $title = single_term_title( 'Cybersecurity Conferences In ', false ); } elseif ( is_tax('country') ) { $title = single_term_title( 'Cybersecurity Conferences In ', false ); } return $title; }
June 7, 2019 at 5:02 am #922502DavidStaffCustomer SupportHave you tried the single_tag_title()
https://developer.wordpress.org/reference/functions/single_tag_title/
-
AuthorPosts
- You must be logged in to reply to this topic.