Add block above description listing

hello, is it possible to add a block containing html before the description? I would like to integrate an adsense script.

For info I already have this code placed before the description:

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$text = $listing->display_avis_knzd();
		
		if(!$text){
			return $blocks;
		}
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'page_content' => [
								'blocks' => [
									'custom_text_above_description' => [
										'type' => 'content',
										'content' => '<p>'.$text.'</p>',
										'_order' => 55,
									],
								],
							],
						],
				]
				)['blocks'];
		},
	1000,
	2
);

Thanks

Please try this PHP snippet instead. Also, please make sure that the listing has an attribute with the field name avis_knzd, as you have tried to display the value of this attribute in your code snippet

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$text = $listing->get_avis_knzd();
		
		if(!$text){
			return $blocks;
		}
		
		return hivepress()->template->merge_blocks(
					$blocks,
					[
						'page_content' => [
								'blocks' => [
									'custom_text_above_description' => [
										'type' => 'content',
										'content' => '<p>'.$text.'</p>',
										'_order' => 55,
									],
								],
							],
				]
				);
		},
	1000,
	2
);

Thanks @yevhen

The problem is that I need a second block because the 1st “avis_knzd” is not displayed on all the listings. The “adsense” block must appear on all listings before the description.

If possible on this order:

  1. Block “adsense”
  2. Block description native to hivepress
  3. Block “avis_knzd”

If you want to show the listing attribute with the field name adsense before the listing description on the listing page, then please change $listing->get_avis_knzd() on $listing->get_ adsense() in the last code snippet

I think I expressed myself badly.

  1. I would like this code to be integrated on all listings (without creating a new attribute and having to manually integrate adsense into each listing) before the description:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="fluid"
     data-ad-layout-key=""
     data-ad-client=""
     data-ad-slot=""></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
  1. Display the attribute “avis_knzd” (code previously provided) after the description actually display before

I hope I was a little more understandable😅

  1. Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress

If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY

  1. Please try this PHP snippet
add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$text = $listing->get_avis_knzd();
		
		if(!$text){
			return $blocks;
		}
		
		return hivepress()->template->merge_blocks(
					$blocks,
					[
						'page_content' => [
								'blocks' => [
									'custom_text_above_description' => [
										'type' => 'content',
										'content' => '<p>'.$text.'</p>',
										'_order' => 70,
									],
								],
							],
				]
				);
		},
	1000,
	2
);