Archived topic
Insert text BEFORE the “tag” title
8 replies · Started by Henry on May 9, 2019
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!
Hi there,
sorry little confused, so are you looking at the permalink structure for the Tag archive or the single post?
I 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!
You 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
Thanks, 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.
In fact - David, ignore my last point - I can use a SEO Plugin that works great.
As usual - amazing support. Thank You!
Glad we could be of help
Hi 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;
}
Have you tried the single_tag_title()
https://developer.wordpress.org/reference/functions/single_tag_title/