• Resolved Pieter Bos

    (@senlin)


    When using the filter to hide the columns in the edit screen (add_filter( 'the_seo_framework_show_seo_column', '__return_false' );) it only seems to be working globally.

    When adding it to a conditional, nothing happens:

    add_action( 'current_screen', 'so_hide_seo_cols_wp_help_screen' );
    
    function so_hide_seo_cols_wp_help_screen() {
    
    	$current_screen = get_current_screen();
    
    	if ( $current_screen ->post_type === 'wp-help' ) {
    		add_filter( 'the_seo_framework_seobox_output', '__return_false' );
    		add_filter( 'the_seo_framework_show_seo_column', '__return_false' ); // doesn't work properly here, only seems to work when applied globally
    	}
    }

    I am trying to hide the columns from the WP Help pages as that is using an internal custom post type only.

    https://www.ads-software.com/plugins/autodescription/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi Piet,

    It’s not working because The SEO Framework was activated before your snippet. This makes the priority higher of The SEO Framework, and your filter will be too late.

    current_screen” also fires after “add_meta_boxes” (source).
    Therefore, you’re required to fall back on the global $post_type, which is given with the action “add_meta_boxes“.

    In conclusion, you require two different actions for the two filters.

    This should sum it up, note it’s theoretical and untested (and with Yoda Conditions), but it should work :)..:

    add_action( 'current_screen', 'so_hide_seo_cols_wp_help_screen', 9 );
    function so_hide_seo_cols_wp_help_screen() {
    
    	$current_screen = get_current_screen();
    	if ( 'wp-help' === $current_screen->post_type ) {
    		add_filter( 'the_seo_framework_show_seo_column', '__return_false' );
    	}
    }
    
    add_action( 'add_meta_boxes', 'so_hide_seo_box_wp_help', 5, 1 );
    function so_hide_seo_box_wp_help( $post_type ) {
    
    	if ( 'wp-help' === $post_type ) {
    		add_filter( 'the_seo_framework_seobox_output', '__return_false' );
    	}
    
    }

    All these actions have been taken into consideration very carefully. Because, with some more convenient and subsequent actions, bugs or incompatibilities arose.

    I hope this helps! Have another great day :)!

    Thread Starter Pieter Bos

    (@senlin)

    Hi Sybre,

    Many thanks for your input.

    Actually, just adding the priority (9) to my original function works ??

    Cheers,
    Piet

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Piet,

    Ah, “add_meta_boxes” runs after “current_screen“. I was browsing the wrong post.php file :).

    Nevertheless, it’s good to hear it works :)!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘filter to hide columns only seems to work globally’ is closed to new replies.