[Support request] Insert text BEFORE the “tag” title

Home Forums Support [Support request] Insert text BEFORE the “tag” title

Home Forums Support Insert text BEFORE the “tag” title

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #893922
    Henry

    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!

    #894028
    David
    Staff
    Customer Support

    Hi there,

    sorry little confused, so are you looking at the permalink structure for the Tag archive or the single post?

    #894169
    Henry

    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!

    #894281
    David
    Staff
    Customer Support

    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

    #894716
    Henry

    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.

    #894724
    Henry

    In fact – David, ignore my last point – I can use a SEO Plugin that works great.

    As usual – amazing support. Thank You!

    #894942
    David
    Staff
    Customer Support

    Glad we could be of help

    #922211
    Henry

    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&nbsp;', false );
        }
        elseif ( is_tax('country') ) {
            $title = single_term_title( 'Cybersecurity Conferences In&nbsp;', false );
        }
        return $title;
    }
    #922502
    David
    Staff
    Customer Support
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.