Add region title and description on frontend, like a category header

Hi again ! :slight_smile:

I would like to add region and description on frontend, like a category header page.
I saw this topic :
Add the region title and description on frontend - General / Geolocation - HivePress Community
Is the same request, but i don’t see the entire solution.

My goal :


Add this header to the region page

For example : this page : Provence-Alpes-Côte d’Azur Archives - Annuaire Drone

How can i modify this page ? I know that the page-header.php in the rentalhive theme is use for the category header, but i don’t know how to apply it on the region page.

I know that with this snippet, i can change the title :

add_filter(
	'hivepress/v1/templates/page',
	function( $args ) {
		if ( is_tax( 'hp_listing_region' ) ) {
			$region = get_queried_object();

			$args['context']['page_title'] = 'Region: ' . $region->name;
		}

		return $args;
	},
	1000
);

but it’s not the solution for me.

Thank you in advance !

Hi,

This would require code customizations, please try adding custom content to the header section via the hivetheme/v1/areas/site_hero filter hook. You can check is_tax('hp_listing_region') and output custom HTML with the title and description. Here’s a sample function from the default ListingHive theme listinghive/includes/components/class-theme.php at master · hivepress/listinghive · GitHub

Hope this helps

Hi !
I managed to do what I wanted. I’m sharing my code to add to the child theme in function.php


function custom_render_region_header_content( $output ) {
    if ( is_tax('hp_listing_region') ) {
        // Récupérer la région actuelle
        $region = get_queried_object();
        $region_title = $region->name;
        $region_description = term_description( $region->term_id, 'hp_listing_region' );

        // Structure HTML inspirée de l'exemple
        $content = '<section class="header-hero hp-listing-category hp-listing-category--view-page">';
        $content .= '<div class="header-hero__content">';
        $content .= '<div class="container">';
        $content .= '<div class="hp-listing-category__header">';
        $content .= '<div class="hp-row">';
        $content .= '<div class="hp-col-sm-6 hp-col-xs-12">';
        
        // Afficher le titre de la région
        $content .= '<h1 class="hp-listing-category__name">' . esc_html( $region_title ) . '</h1>';
        
        // Afficher la description de la région
        if ( $region_description ) {
            $content .= '<div class="hp-listing-category__description has-medium-font-size">';
            $content .= wp_kses_post( $region_description ); // Affiche le texte brut sans balises <p>
            $content .= '</div>';
        }

        $content .= '</div>';
        $content .= '</div>';
        $content .= '</div>';
        $content .= '</div>';
        $content .= '</div>';
        $content .= '</section>';

        // Ajouter le contenu Ă  la sortie de l'en-tĂŞte
        $output = $content;
    }
    return $output;
}
add_filter( 'hivetheme/v1/areas/site_hero', 'custom_render_region_header_content' );


add_filter( 'hivepress/v1/templates/listing_region_view_page', function( $template ) {
	return hivepress()->template->merge_blocks(
		$template,
		[
			'page_content' => [
				'blocks' => [
					'listing_region_header' => null, // Supprime le header par défaut
				],
			],
		]
	);
} );

But I can’t hide the old title display here:

How can I do this?
Thanks in advance!

Not sure I get your point, but to hide the title this CSS snippet should do :

body.tax-hp_listing_region .hp-page__title {
    display: none;
}

Likewise, you could hide the duplicate description by using hp-page__description.

1 Like

Thanks for sharing! You can try removing the title via the CSS snippet suggested above, or using PHP via the hivepress/v1/templates/listings_view_page filter hook, checking the is_tax('hp_listing_region') condition.

Thank you for your awnser.
It’s ok via css, but i want to disable it via php.

I tried this code, but it doesn’t work. Do you have any tips? Where is my mistake?

add_filter(
	'hivepress/v1/templates/listings_view_page',
	function( $template ) {
		// Appliquer uniquement sur les pages de région
		if ( is_tax( 'hp_listing_region' ) ) {
			// Supprimer le bloc de titre
			unset( $template['blocks']['page_title'] );

			// Supprimer le bloc de description
			unset( $template['blocks']['term_description'] );
		}

		return $template;
	},
	100
);

If i try this code, i can disable the title, but not for description :

add_filter(
	'hivepress/v1/templates/page',
	function( $args ) {
		if ( is_tax( 'hp_listing_region' ) ) {
			// Supprime le titre de la page
			unset( $args['context']['page_title'] );

			// Supprime le bloc de description de la page (le bon tableau ici est "blocks")
			unset( $args['blocks']['term_description'] );
		}

		return $args;
	},
	1000
);

Thank you !

Hi,

In your second PHP snippet, we recommend replacing unset( $args['blocks']['term_description'] ); with unset( $args['context']['page_description'] );. And check if everything is working correctly.

Hi !
It’s all good :slight_smile:
all-good-its-all-good

Thank you !

1 Like