Last active
February 9, 2017 19:01
-
-
Save robneu/10694943 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment