Site logo

[Resolved] Display Rules for Elements based on Custom Fields?

Home Forums Support [Resolved] Display Rules for Elements based on Custom Fields?

Home Forums Support Display Rules for Elements based on Custom Fields?

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #1701996
    David
    Staff
    Customer Support

    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

    #1702050
    Randy

    Perfect! That worked. Thanks!

    #1702289
    David
    Staff
    Customer Support

    Glad to hear that!

    #1929682
    Rekindle

    This works so well! Thanks Tom.

    #1936324
    David
    Staff
    Customer Support

    Glad to hear you found this useful!

    #2177227
    Baptiste

    Note : for me, generate_hook_element_display did not work, but generate_element_display did 😉

    #2227254
    Sam

    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 );
    #2227533
    David
    Staff
    Customer Support

    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.

Viewing 8 posts - 16 through 23 (of 23 total)
  • You must be logged in to reply to this topic.