- This topic has 9 replies, 2 voices, and was last updated 1 year, 8 months ago by David.
-
AuthorPosts
-
August 5, 2022 at 3:44 am #2304079Tesco
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?
August 5, 2022 at 5:24 am #2304145DavidStaffCustomer SupportHi 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/
August 5, 2022 at 5:52 am #2304172TescoHi 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; };
August 5, 2022 at 5:58 am #2304181DavidStaffCustomer SupportWhat is it meant to do ?
August 5, 2022 at 6:22 am #2304188TescoReplace the h1 title by a string in a variable
August 5, 2022 at 7:07 am #2304233DavidStaffCustomer SupportI 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.August 5, 2022 at 9:44 am #2304539TescoYou 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>
August 6, 2022 at 2:52 am #2304961DavidStaffCustomer SupportThis 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:
the999
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
variableAugust 6, 2022 at 5:02 am #2305026TescoYou’re great (as usual)! I appreciated the explanations.
Thanks!
August 7, 2022 at 3:21 am #2305611DavidStaffCustomer SupportGlad to be of help!
-
AuthorPosts
- You must be logged in to reply to this topic.