Skip to content

Instantly share code, notes, and snippets.

@nicdford
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdford/a979872f5314b1e53e43 to your computer and use it in GitHub Desktop.
Save nicdford/a979872f5314b1e53e43 to your computer and use it in GitHub Desktop.
Conditionally disable the Yoast Page Analysis on admin edit screens.
/**
* 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' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment