- This topic has 3 replies, 2 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
December 13, 2022 at 2:29 am #2460120
Samuel
Hi,
just found this article: https://generatepress.com/forums/topic/display-woocommerce-endpoint-title-in-header-element/
My question is: Is it possible to implement the whole thing better somehow? Now that GBlocks can also output dynamic content?
My problem is the following: I have an element with the following setting https://app.screencast.com/tPDCTILHMMmyR
At the endpoint /lost-password/ a H1 heading appears twice now.
https://app.screencast.com/jkclmMSv1NhhZ
“Forgot password” should either be in the header. So position 1. or the title should not be H1, but H2.
December 13, 2022 at 4:36 am #2460277David
StaffCustomer SupportHi there,
for reference here is the function Woo uses to display the Endpoint title:
One of its conditional template tags is
in_the_loop()which stops it from affecting other elements such as menu items that also use thethe_titlefilter. Which is why it won’t work with a Page Hero that is hooked in outside the loop.So one option would be to repurpose the woo function in a render_block filter.
1. The Page Hero would have to be specific to the Account page.
1.1 The H1 Headline should contain a static title string ( not dynamic ) eg.My Account.
1.2 In Advanced > Additional CSS Class(es) add a class eg.endpoint-title2. Add this PHP Snippet and update the
$stringand$classvariables to match 1.1 and 1.2:add_filter( 'render_block', function( $block_content, $block ) { global $wp_query; if ( ! is_null( $wp_query ) && ! is_admin() && is_main_query() && is_page() && is_wc_endpoint_url() ) { $endpoint = WC()->query->get_current_endpoint(); $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; $endpoint_title = WC()->query->get_endpoint_title( $endpoint, $action ); $title = $endpoint_title ? $endpoint_title : $title; $string = 'My Account'; // String to replace $class = 'endpoint-title'; // block class to target if ( ! empty( $block['attrs']['className'] ) && $class === $block['attrs']['className'] ) { $block_content = str_replace( $string , $title , $block_content ); } } return $block_content; }, 10, 2 );December 30, 2022 at 1:32 am #2477670Samuel
Thanks David!
December 30, 2022 at 2:12 am #2477694David
StaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.