Created
April 3, 2016 19:08
-
-
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.
This file contains 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 | |
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