Only show add listing button on header if you are signed is as a specific user

Hey guys,

So I’m trying to hide the add listing buttons if you are not signed in on the page.

I tried this code snippet from a different topic but now it just doesn’t show the button even if I’m signed in as an administrator.

This is the code snippet I’m using and it’s not working.

add_filter(
    'hivepress/v1/templates/site_header_block',
    function( $template ) {
		if(is_user_logged_in()){
            		$template = hivepress()->helper->merge_trees(
						$template,
						[
							'blocks' => [
								'listing_submit_link' => [
									'type' => 'content',
								],
							],
						]
					);
		}else{
			$template = hivepress()->helper->merge_trees(
				$template,
				[
					'blocks' => [
						'listing_submit_link' => [
							'type' => 'content',
						],
					],
				]
			);
		}

    return $template;
    },
    1000
);

Please try this PHP snippet

add_filter(
	'hivepress/v1/templates/site_header_block',
	function($template){
		if(is_user_logged_in()){
			return $template;
		}
		
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'listing_submit_link' => [
						'type' => 'content',
					],
				],
			]
		);
	},
	 1000
);

It worked! Thank you!

Hello, snippet applied, but any registered users can still List a Property… is it possible to only admit listings from SPECIFIED users (1 or 2 users)? Not all registered users? Thanks a lot

It is possible to hide Add a Listing button for specific user roles. Please check this topic Add Listing Button Visible by Role | HivePress Support

2 Likes

Thank you!:wink: