Tagged: x
-
AuthorPosts
-
February 3, 2017 at 12:54 pm #1357067
ptmarketingParticipantIn 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/
February 3, 2017 at 9:25 pm #1357578
RadModeratorHi 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.
February 16, 2017 at 4:09 pm #1374143
ptmarketingParticipantYes, 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__' )February 17, 2017 at 12:00 am #1374591
Rue NelModeratorHello 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.
Hope this helps.
February 17, 2017 at 1:20 pm #1375420
ptmarketingParticipantHi 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!
February 17, 2017 at 11:21 pm #1375959
RadModeratorHi 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.
February 17, 2017 at 11:25 pm #1375960
Rue NelModeratorHello 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.
February 21, 2017 at 5:04 pm #1380488
ptmarketingParticipantGreat, thank you both for your help!
February 21, 2017 at 6:10 pm #1380534
NicoModeratorHappy to hear that.
Feel free to ask us again.
Thanks.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1357067 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
