Skip to content

Instantly share code, notes, and snippets.

@dingo-d
Created April 3, 2016 19:08
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 dingo-d/a930935ad98c6f4a8a5b2db530d61be3 to your computer and use it in GitHub Desktop.
Save dingo-d/a930935ad98c6f4a8a5b2db530d61be3 to your computer and use it in GitHub Desktop.
A code that will make sure you enqueue your custom scripts only on pages you need.
<?php
if ( !function_exists('mytheme_is_admin_page') ) {
function mytheme_is_admin_page($new_edit = null){
global $pagenow;
if (!is_admin()) return false;
if($new_edit == "edit") { // if is edit post page
return in_array( $pagenow, array( 'post.php', ) );
} elseif($new_edit == "new") { // if is new post page
return in_array( $pagenow, array( 'post-new.php' ) );
} elseif($new_edit == "upload") { // if is media page
return in_array( $pagenow, array( 'upload.php' ) );
} elseif($new_edit == "options") { // if is settings page
return in_array( $pagenow, array( 'options-general.php' ) );
} else {
return in_array( $pagenow, array( 'post.php', 'post-new.php', 'upload.php', 'options-general.php' ) );
}
}
}
// Only enqueue backend styles/scripts if on certain page(s)
if ( travelnews_is_admin_page('new') || travelnews_is_admin_page('edit') ) {
add_action('admin_enqueue_scripts', 'mytheme_backend_scripts');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment