- This topic has 4 replies, 2 voices, and was last updated 4 years, 9 months ago by Tom.
-
AuthorPosts
-
July 8, 2019 at 4:58 pm #952485Aäron
Hi GeneratePress,
Firstly, thanks for the great theme! With just a few plugins I get consistent 100/100 scores on Google Pagespeed Insights! 🙂
I’m in the process further of optimizing my website for search engines before I will start posting more content. So far I have succeeded in altering the URL, and page titles to my wish, but not the category page titles. I would like the category page titles to also include the parent category title. What am I doing wrong? I have the latest version of GP Theme and GP Premium, I have tried disabling all my plugins, clearing caches, tried all kinds of hooks, but all to no avail.
This is the code in functions.php that I think should work (it works for a different hook on the HTML-page-titles), but could you please also have a look at it?
add_filter( 'get_the_archive_title' ,'custom_category_page_title' ); function custom_category_page_title ($title) { if( is_category() ) { $current_category = get_queried_object(); $current_category_id = $current_category->term_id; $categories = get_category_parents($current_category_id, 'false', ' '); $title = $categories; } return $title; }
Kind regards,
Aäron
July 9, 2019 at 8:51 am #953085TomLead DeveloperLead DeveloperHi there,
What about this?:
add_filter( 'get_the_archive_title', function( $title ) { if ( is_category() ) { $cat = get_the_category(); $parentCatName = get_cat_name($cat[0]->parent); if ( ! empty( $parentCatName ) ) { $title = $parentCatName . ' : ' . $title; } } return $title; } );
Let me know 🙂
July 9, 2019 at 9:56 am #953150AäronHi,
Thanks! Unfortunately it does not solve my problem. It concerns for example this page: https://itreport.info/gartner/market-guide/. I would like the title to be “Gartner Market Guide” instead of just “Market Guide”. Any hints on where else I could look / make changes?
Kind regards, Aäron
July 9, 2019 at 1:59 pm #953340AäronSuccess! The problem was the priority in the add_filter: it was too low.
The working code:
add_filter( 'get_the_archive_title', 'filter_category_page_title', 100, 1); function filter_category_page_title ($title) { if( is_category() ) { $current_category = get_queried_object(); $current_category_id = $current_category->term_id; $categories = get_category_parents($current_category_id, 'false', ' '); $title = $categories; } return $title; }
July 9, 2019 at 3:21 pm #953409TomLead DeveloperLead DeveloperAwesome, glad you got it working 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.