Site logo

Archived topic

Display Rules for Elements based on Custom Fields?

22 replies · Started by Eric on April 30, 2019

Viewing posts 16–23 of 23

Aah ok - you should be able to use this PHP Snippet:

add_filter('wp_sitemaps_taxonomies', function( $taxonomies ) {
      unset( $taxonomies['your_taxonomy_name_here'] );
      return $taxonomies;
  }
);

replace your_taxonomy_name_here with the tax name - in the original example that would be: element-controls

Perfect! That worked. Thanks!

Glad to hear that!

This works so well! Thanks Tom.

Glad to hear you found this useful!

Note : for me, generate_hook_element_display did not work, but generate_element_display did ;)

Same experience/finding here as Baptiste; I had to use generate_element_display.

In my case, I'm checking the ACF field on an Options Page, so my version is:

add_filter( 'generate_element_display', function( $display, $element_id ) {
	if ( 123 === $element_id ) {
		$your_field = get_field( 'your_custom_field', 'option' );
		
		if ( ! $your_field || $your_field == false ) {
			$display = false;
		}
	}

	return $display;
}, 10, 2 );

Thanks for sharing guys.

For some background regarding display filter, each GP Element originally had its own filter eg.

Hook: generate_hook_element_display
Block: generate_block_element_display
Layout: generate_layout_element_display
Header: generate_header_element_display

However we more recently introduced the generate_element_display which is present in ALL GP Elements. So can be used for any element type in place of the above.

This archived topic is closed to new replies.