gbissland
2/9/2017 - 7:01 PM

disable-yoast-analysis-post-page.php

<?php

add_action( 'init', 'prefix_disable_post_page_analysis' );
/**
 * Conditionally disable the Yoast Page Analysis on post and page admin edit screens.
 *
 * @uses   prefix_is_edit_screen
 * @return NULL if we're not on the right admin screen
 * @author Robert Neu <http://wpbacon.com>
 * @link   http://auditwp.com/wordpress-seo-admin-columns/
 */
function prefix_disable_post_page_analysis() {
	if ( ! prefix_is_edit_screen( array( 'post', 'page' ) ) ) {
		return;
	}
	// Disable Yoast admin columns.
	add_filter( 'wpseo_use_page_analysis', '__return_false' );
}
<?php

/**
 * Helper function to determine if we're on the right edit screen.
 *
 * @global  $pagenow
 * @param   $post_types array() optional post types we want to check.
 * @return  bool
 */
function prefix_is_edit_screen( $post_types = '' ) {
	if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
		return false;
	}
	global $pagenow;
	// Return true if we're on any admin edit screen.
	if ( ! $post_types && 'edit.php' === $pagenow ) {
		return true;
	}
	elseif ( $post_types ) {
		// Grab the current post type from the query string and set 'post' as a fallback.
		$current_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'post';
		foreach ( $post_types as $post_type ) {
			// Return true if we're on the edit screen of any user-defined post types.
			if ( 'edit.php' === $pagenow && $post_type === sanitize_key( $current_type ) ) {
				return true;
			}
		}
	}
	return false;
}

add_action( 'init', 'prefix_maybe_disable_page_analysis' );
/**
 * Conditionally disable the Yoast Page Analysis on admin edit screens.
 *
 * @uses   prefix_is_edit_screen
 * @return NULL if we're not on the right admin screen
 * @author Robert Neu <http://wpbacon.com>
 * @link   http://auditwp.com/wordpress-seo-admin-columns/
 */
function prefix_maybe_disable_page_analysis() {
	if ( ! prefix_is_edit_screen() ) {
		return;
	}
	// Disable Yoast admin columns.
	add_filter( 'wpseo_use_page_analysis', '__return_false' );
}