Shoora
10/3/2018 - 4:40 AM

Hooks to disable Yoast SEO plugin features and admin screen controls.

Hooks to disable Yoast SEO plugin features and admin screen controls.

<?php
/*******************************
 =Yoast SEO Hooks (includes Premium)
  ******************************/
 /* Remove default redirects feature, for posts and term.
  * @link https://kb.yoast.com/kb/how-to-disable-automatic-redirects/
  */
add_filter('wpseo_premium_post_redirect_slug_change', '__return_true' );
add_filter('wpseo_premium_term_redirect_slug_change', '__return_true' );

/* Use Yoast SEO's Primary Category feature only on Categories. */
function my_yoast_prime_cats( $all_taxonomies ) {
    $args = array( 'name' => 'category' );
    $all_taxonomies = get_taxonomies( $args, 'objects' );
 
    return $all_taxonomies;
}
add_filter('wpseo_primary_term_taxonomies', 'my_yoast_prime_cats' );

/**
 * Disable the WPSEO v3.1+ Primary Category feature.
 */
// add_filter( 'wpseo_primary_term_taxonomies', array( 'custom-tax' ) );

/* Remove the Yoast SEO columns from admin lists. */
function my_remove_yoast_cols( $columns ) {
    unset( $columns['wpseo-title'] );
    unset( $columns['wpseo-metadesc'] );
    unset( $columns['wpseo-focuskw'] );
    unset( $columns['wpseo-links'] );
    unset( $columns['wpseo-score'] );
    unset( $columns['wpseo-score-readability'] );

    return $columns;
}
add_filter ( 'manage_edit-post_columns', 'my_remove_yoast_cols' );
add_filter ( 'manage_edit-page_columns', 'my_remove_yoast_cols' );

/* Remove Yoast SEO filter dropdowns on All Posts|Pages screens (e.g., "All SEO Scores"). */
function hmy_remove_yoast_posts_filters() {
    global $wpseo_meta_columns;

    if ( $wpseo_meta_columns ) { // Remove "All SEO Scores" and "All Readability Scores".
        remove_action( 'restrict_manage_posts', array( $wpseo_meta_columns, 'posts_filter_dropdown' ) );
        remove_action( 'restrict_manage_posts', array( $wpseo_meta_columns, 'posts_filter_dropdown_readability' ) );
    }
}
add_action( 'admin_init', 'my_remove_yoast_posts_filters', 20 );