[Resolved] Filter category title

Home Forums Support [Resolved] Filter category title

Home Forums Support Filter category title

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2304079
    Tesco

    Just saw the filters list and I didn’t see any one that could fit…

    Is there any way of filtering the category and archives title?

    #2304145
    David
    Staff
    Customer Support

    Hi there,

    GP uses the core get_the_archive_title function, which has its own hook:

    https://developer.wordpress.org/reference/hooks/get_the_archive_title/

    #2304172
    Tesco

    Hi David,

    Can you help me out here?

    I’m trying this code but it’s not working…

    add_filter( 'get_the_archive_title', 'f_archive_title');
    function f_archive_title ($title) {
    	// variable
    	$my_variable = "This is my variable to replace the cat title";
      if ( is_category() ) {
        $title= '<h1 class="entry-title"%1$s>%2$s ' . $cat_meta['h1_custom_title'] . 'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : '</h1>';
      }
      return $title;
    };
    #2304181
    David
    Staff
    Customer Support

    What is it meant to do ?

    #2304188
    Tesco

    Replace the h1 title by a string in a variable

    #2304233
    David
    Staff
    Customer Support

    I don’t know what this is for:

    $time = get_post_meta($post->ID, 'time', true);

    And haw was the option added to the Category Term? And does that work ?

    Last thing i can say is $title is a string, you don’t need the HTML as you’re only returning the string value.

    #2304539
    Tesco

    You can forget $time = get_post_meta($post->ID, 'time', true); and the option added to the Category Term.

    I just need a way to change the category title by a value returned from my database what will be the string inside the variable (it can be any variable) I mentioned earlier.

    Corrected the code above…

    I found out that this is the way the theme renders what I need to filter using the function generate_archive_title:

    <h1 class="page-title"><?php the_archive_title(); ?></h1>

    Desired in archive.php is:

    Replace this: <h1>Category Name</h1>

    By this: <h1>My Custom Category Title</h1>

    #2304961
    David
    Staff
    Customer Support

    This is the basics of the function:

    add_filter( 'get_the_archive_title', 'f_archive_title', 999 );
    function f_archive_title ($title) {
        $custom_title = 'your custom title';
        if ( is_category() ) {
            $title = $custom_title ;
        }
        return $title;
    };

    Notes:
    the 999 on the first line, that is the filter hook Priority and it will make sure that THIS function callback is after all the others.

    the $custom_title is just the text string, theres no need for the HTML as the Theme does that for you.

    Now you just need to decide on where you will save your custom title and load that into the $custom_title variable

    #2305026
    Tesco

    You’re great (as usual)! I appreciated the explanations.

    Thanks!

    #2305611
    David
    Staff
    Customer Support

    Glad to be of help!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.