Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1357067
    ptmarketing
    Participant

    In a post category archive page, why does the H1 page title in the header display “Category Archive” while the the page title found in the <head> displays the name of the category followed by “Archives” (e.g. “News Archives”)?

    Why is the function below unable to override the H1 page title? How do we override the “Category Archive” H1 heading using a function?

    function change_category_archive_title( $title ) {
        if ( is_category() ) {
            $title = single_cat_title( '', false );
    	}
        return $title;
    }
    add_filter( 'get_the_archive_title', 'change_category_archive_title' );

    Example page on our website: http://www.picturethisgallery.com/category/framing/

    #1357578
    Rad
    Moderator

    Hi there,

    Thanks for writing in.

    Maybe you have SEO plugin that overrides title? The one you’re referring is a landmark. You can change it by editing the category at Admin > Posts > Categories and change its title.

    Thanks.

    #1374143
    ptmarketing
    Participant

    Yes, thank you! The title is being override by an SEO plugin.

    Next question: how can I override the Landmark Title using a function? The template file contains the following code:

    $title = ( $meta['archive-title'] != '' ) ? $meta['archive-title'] : __( 'Category Archive', '__x__' );

    What does the following code do? Is it possible to override this without editing the template file, perhaps with something in functions.php instead?

    __( 'Category Archive', '__x__' )

    #1374591
    Rue Nel
    Moderator

    Hello There,

    Thanks for updating in! You can override the Category Landmark titles in the dashboard without having to use any code. Simply go to Posts > Categories and edit the category archive title.

    http://prntscr.com/e9s2yf

    Hope this helps.

    #1375420
    ptmarketing
    Participant

    Hi Rue, thanks for your reply. Yes, I believe your answer is the same as Rad’s previous reply.

    Next question: how can I instead override this using a function, and ignoring the settings in Admin> Posts > Categories?

    The reason is that the workflow should be as simple as possible for our editors, and this would help in that regard.

    Thanks!

    #1375959
    Rad
    Moderator

    Hi there,

    Ah, you wish to change the default string? Please add this code to your child theme’s functions.php

    add_filter( 'gettext', 'category_title_override', 20, 3 );
    
    function category_title_override( $translated_text, $text, $domain ) {
    
       return is_category() && $text == 'Category Archive' ? 'Your new category title' : $translated_text;
    
    }

    Or if you wish to override the saved meta, then add this too

    add_action('init', 'override_category_meta_init', 9999 );
    
    function override_category_meta_init () {
    if ( is_category() ) {
      
      $object = get_queried_object();
      $id     = $object->term_id;
      $meta   = get_option( 'taxonomy_' . $id );
      
      add_filter( 'taxonomy_' . $id, 'override_category_meta', 20, 2 );
    
    }
    }
    
    function override_category_meta ( $value, $option ) {
    
    if ( is_category() ) {
      
      $object = get_queried_object();
      $id     = $object->term_id;
      
      return $option == 'taxonomy_' . $id ? 'Your new category title' : $value;
    
    }
    
    return $value;
    
    }

    Hope this helps.

    #1375960
    Rue Nel
    Moderator

    Hello There,

    Thanks for updating in! I am afraid that it is no longer possible because there aren’t any filter that we can hook into. You will have to add some condition in the landmark-header.php file instead.

    Thank you for your understanding.

    #1380488
    ptmarketing
    Participant

    Great, thank you both for your help!

    #1380534
    Nico
    Moderator

    Happy to hear that.

    Feel free to ask us again.

    Thanks.

  • <script> jQuery(function($){ $("#no-reply-1357067 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>