WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] Remove SEO for custom post type (6 posts)

  1. itinerant
    Member
    Posted 2 years ago #

    Plugin Version: 1.2.5

    Apologies if I've missed something obvious, I haven't delved through this plugin code before.

    Goal:
    1) I don't want the Yoast SEO to do anything for a particular custom post type. My use case is that it is not public.
    2) I do want it on everything else.
    3) I do want to leave in the analysis functionality for normal pages/pages and other custom post types (that means I do not want to completely disable it using the wpseo_use_page_analysis filter )

    What I have done:
    I can't find a filter to block Yoast SEO from being enabled for a particular custom post type, but setting up the custom post type up as public=>false does disable most but not all of the Yoast WP SEO functionality. This is fine for my use case as the custom post type is not publicly viewable on its own pages. (Note if the post type is publicly viewable then most of the admin output can be disabled using the Post Types WordPress SEO Meta Box hide option aka hideeditbox-post_type).

    That's great but there's still some functionality I don't want to happen which is generated by this code in the metabox class:

    add_filter( 'request', array( $this, 'column_sort_orderby' ) );
     add_action( 'restrict_manage_posts', array( $this, 'posts_filter_dropdown' ) );
     add_action( 'post_submitbox_misc_actions', array( $this, 'publish_box' ) );

    As they are nicely set up using actions and filters we should be able to remove them quite easily. I have put this on the admin_init hook to fire after the Yoast SEO functionality

    remove_filter( 'request', array( $wpseo_metabox, 'column_sort_orderby' ) );
    remove_action( 'restrict_manage_posts', array( $wpseo_metabox, 'posts_filter_dropdown' ) );
    remove_action( 'post_submitbox_misc_actions', array( $wpseo_metabox, 'publish_box' ) );

    However that can only work if $wpseo_metabox has global scope which it doesn't. Adding global $wpseo_metabox just before it is defined means I can now disable it for my custom post type, but obviously it's not a long term solution.

    Solutions:

    Any chance of an update to make $wpseo_metabox global so themes and other plugins can play nicely with this excellent SEO plugin?

    A better general solution would be the ability to completely exclude some custom post types from WordPress SEO.

    Any other ideas - am I missing something obvious? Or should I be using an earlier hook to disable WordPress SEO from loading at all (for example using the WP $typenow global)?

    Help appreciated.

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. itinerant
    Member
    Posted 2 years ago #

    Doh! Contrary to what I said in Goal(3), a much simpler way to do what I need in the admin is to add a filter on wpseo_use_page_analysis

    `global $typenow;
    if ('post_type' == $typenow) {
    return false;
    } else {
    return true;
    }

    It'd still be more flexible if the actions and filters could be individually removed from a theme, and I think that means exposing the classes globally.

    And I'm still not sure if it would be better to completely disable the plugin for a particular post type.

  3. snowboardmommy
    Member
    Posted 1 year ago #

    I would also like to chime in for a "hide" option for the "check SEO" in the submit box meta box, and also to hide the SEO link in the admin bar for those who do not have permission to use it anyway.

    I have figured out how to remove "SEO" from my admin bar, but I cannot get the remove_action to work to get rid of the "SEO check" from the submit meta box on my custom post types. It does not appear to do anything there, but it will still confuse several of my clients. Since I can remove the other SEO meta boxes on the custom post type, it would be nice to remove ALL the SEO features from the custom post type.

    Thanks!

  4. Greg
    Member
    Posted 1 year ago #

    I've been trying to achieve the same goals. This worked right away for me: http://wordpress.org/support/topic/enable-yoast-seo-in-custom-post-type?replies=4#post-4299305

  5. itinerant
    Member
    Posted 1 year ago #

    You must have wanted something different. This is about disabling the parts that using public=>false does not disable, and the filter I subsequently posted does that for the page analysis.

    As I noted at the start:
    I can't find a filter to block Yoast SEO from being enabled for a particular custom post type, but setting up the custom post type up as public=>false does disable most but not all of the Yoast WP SEO functionality.

    To get rid of the publish box was much harder and I ended up with this

    /* Remove Yoasts publish box which is output even when post is not public
    * Hook this to current_screen, the first time $typenow is set up and before the publish box action
    * Custom Type is not available on admin_init so his filter is no help
    * Ridiculous hard graft to remove it as can't get at the WPSEO_metabox instance either, so scan the wp filter store to track it down
    */
    public static function creative_infusion_remove_yoast_seo(){
    global $typenow, $wp_filter;
    if ($typenow=='yourcustomposttype' && isset($wp_filter['post_submitbox_misc_actions']['10'])) {
    $filters=$wp_filter['post_submitbox_misc_actions']['10'];
    foreach ($filters as $idx=>$data) {
    $function=$data['function'][0];
    if ( is_object($function) && is_a($function, 'WPSEO_Metabox') ) {
    remove_action( 'post_submitbox_misc_actions', array( $function, 'publish_box' ) );
    }
    }
    }
    }
    add_action('current_screen', 'creative_infusion_remove_yoast_seo');

  6. itinerant
    Member
    Posted 1 year ago #

    Sorry forgot the code tags

    /* Remove Yoasts publish box which is output even when post is not public
    * Hook this to current_screen, the first time $typenow is set up and before the publish box action
    * Custom Type is not available on admin_init so his filter is no help
    * Ridiculous hard graft to remove it as can't get at the WPSEO_metabox instance either, so scan the wp filter store to track it down
    */
    public static function creative_infusion_remove_yoast_seo(){
        global $typenow, $wp_filter;
        if ($typenow=='yourcustomposttype' && isset($wp_filter['post_submitbox_misc_actions']['10'])) {
            $filters=$wp_filter['post_submitbox_misc_actions']['10'];
            foreach ($filters as $idx=>$data) {
                $function=$data['function'][0];
                if ( is_object($function) && is_a($function, 'WPSEO_Metabox') ) {
                    remove_action( 'post_submitbox_misc_actions', array( $function, 'publish_box' ) );
                }
            }
        }
    }
    add_action('current_screen', 'creative_infusion_remove_yoast_seo');

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic