- This topic has 11 replies, 2 voices, and was last updated 1 year, 11 months ago by Ying.
-
AuthorPosts
-
May 25, 2022 at 11:41 am #2232601Tom
I need to insert some text before the <h1> tag archive title on every tag page.
For example let’s say the tag is called “rhubarb”. On the tag archive page for all things “rhubarb”, I need to change the <h1> from <h1>Rhubarb</h1> to <h1>Added text Rhubarb</h1>
To be clear – the “Added text” need to be added before all other tag titles as well.
The site is a dev site I’m converting from an older theme.
The previous theme used this functions.php snipped to achieve the above:
—————
// Tag Archive if ( is_tag() ) { $title = __( 'Added text ', 'woothemes' ) . single_tag_title( '', false ); } // Allow for external filters to manipulate the title value. $title = apply_filters( 'woo_archive_title', $title, $before, $after ); if ( $echo ) echo $title; else return $title; } // End woo_archive_title()
Please can you let me know how I can achieve the same in GeneratePress pro using a functions snippet?
Thanks.
May 25, 2022 at 11:54 am #2232607YingStaffCustomer SupportHi Tom,
You can easily achieve this using a block element – page hero:
https://docs.generatepress.com/article/block-element-page-hero/When you enable the dynamic data for headline block, there’s field called
before text
, you can simply add the text in to that field.
https://www.screencast.com/t/jvJ7VWFoMay 25, 2022 at 11:58 am #2232610TomSorry if I was not clear. I’m talking about a tag archive, not a page or a post; so I cannot use a block element since there’s no way to use a block element in a tag archive.
More information on WordPress tags:
https://developer.wordpress.org/reference/functions/single_tag_title/May 25, 2022 at 12:16 pm #2232624YingStaffCustomer Supportso I cannot use a block element since there’s no way to use a block element in a tag archive.
Why would you think that way? A block element can be assigned to all archives, including tag archive.
May 25, 2022 at 12:23 pm #2232629TomI would think that way because it isn’t possible?
If you think it is possible, please provide a complete walk through and I’ll be happy to try it.
Otherwise, please could you provide a functions.php code snippet, as requested, because the documentation on Generatepress hooks and filters isn’t very clear in this respect and I’m asking for support with this.
Thanks for your understanding.
May 25, 2022 at 12:31 pm #2232637YingStaffCustomer SupportI think a smart person like you should be able to figure out after watching this video, it’s a step by step tutorial 🙂
https://youtu.be/L1KtrKJIFzkMay 25, 2022 at 12:35 pm #2232638TomI believe your suggestion requires the block element to disable (strip out) the existing tag archive title and replace it with a new dynamic title as defined by the block element, which is then printed as an <h1>.
This isn’t what I’m looking for.
I need to keep the existing tag title, but simply add (print) text before it.
On the site I’m working on it’s very important that the existing tag titles are retained since this data is used for various filters and external applications. It’s no use if the entire tag title is changed. That’s why the text needs to be added to the <h1>, and not the tag title changed. I hope this is clear.
The best way to do this would be a functions snippet as I suggested, which is why I’m asking for your support assistance with this.
May 25, 2022 at 12:38 pm #2232642YingStaffCustomer SupportI see.
So the tag archive is product tag archive? not post tag archive?
May 25, 2022 at 12:40 pm #2232645TomNo, it’s a post tag archive.
May 25, 2022 at 12:51 pm #2232659YingStaffCustomer SupportTry this, just replace
Your text here
with your text.add_action('wp',function() { if (is_tag()) { remove_action( 'generate_archive_title', 'generate_archive_title' ); add_action( 'generate_archive_title', 'generate_custom_tag_archive_title' ); } }); /** * Build the archive title * * @since 1.3.24 */ function generate_custom_tag_archive_title() { if ( ! function_exists( 'the_archive_title' ) ) { return; } ?> <header <?php generate_do_attr( 'page-header' ); ?>> <?php /** * generate_before_archive_title hook. * * @since 0.1 */ do_action( 'generate_before_archive_title' ); ?> <h1 class="page-title"> Your text here <?php the_archive_title(); ?> </h1> <?php /** * generate_after_archive_title hook. * * @since 0.1 * * @hooked generate_do_archive_description - 10 */ do_action( 'generate_after_archive_title' ); ?> </header> <?php }
May 25, 2022 at 1:05 pm #2232668TomThat’s perfect. Thanks so much for your help with this. 🙂
May 25, 2022 at 1:17 pm #2232678YingStaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.