Add new class to element

Hi,

I would like to add a new class to an element of Hive, in Listing Title, both on blocks and on Listing page.
I checked this ticket (Change sidebar classes) but with no success.


add_filter(
	'hivepress/v1/templates/listing_view_page',
	function( $template ) {

		$block = hivepress()->template->fetch_block($template, 'page_content');
		
		if(!$block){
			return $template;
		}
			
		// Set new classes.
		$block['listing_title']['attributes']['class'] = [ 'hp-listing__title', 'notranslate'];
		
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_container' => [
						'blocks' => [
							'page_content' => $block		
						],
					],
				],
			]
		);
	},
	1000
);

I changed the code and I got this but this is not workig, Iā€™m trying to add a new class called notranslate on this element, this will be on listing view page, the title and then I would like to add on listing blocks also.

Can you check what is missing on this code please?

Regards

Thank you for waiting. Please try this PHP code snippet

add_filter('hivepress/v1/templates/listing_view_block', 'custom_alter_listing_block_page', 1000);
add_filter('hivepress/v1/templates/listing_view_page', 'custom_alter_listing_block_page', 1000);

function custom_alter_listing_block_page($template){
	return hivepress()->template->merge_blocks(
		$template,
		[
			'listing_title' => [
				'attributes' => [
					'class' => ['hp-listing__title', 'notranslate'],
				]
			]
		]
	);
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.