In functions.php of my theme I have code to add page in admin area and append scripts to it. But scripts are not loaded. Bellow is code. Commented out add_action lines are the one I did check.
// functions.php
// Append user style and scripts to Add New Wallpaper menu
function pb_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script('pb-upload', get_template_directory_uri() . '/pb-upload.js');
wp_enqueue_script('pb-upload');
}
function pb_admin_style() {
wp_enqueue_style('thickbox');
}
function pb_wallpaper_adminmenu() {
$page = add_menu_page('Dodaj TapetÄ', 'Dodaj TapetÄ', 'edit_posts', 'add-wallpaper', 'pb_add_wallpaper', '', 6);
}
// add_action( 'admin_head-add-wallpaper', 'pb_admin_scripts');
// add_action( 'admin_print_scripts-add-wallpaper', 'pb_admin_scripts');
// add_action( 'admin_print_styles-add-wallpaper', 'pb_admin_style');
// add_action( 'load-add-wallpaper', 'pb_admin_scripts');
// add_action( 'load-add-wallpaper', 'pb_admin_style');
// add new wallpaper
function pb_add_wallpaper() {
?>
<div class="wallpaper-add">
<h3>Dodaj NowÄ
TapetÄ</h3>
<form method="post" action="">
<input type="hidden" name="action" value="pb_add_wallpaper" />
<input id="upload_image_button" type="button" value="Upload Image" />
<input type="hidden" name="upload_image" id="upload_image" />
<?php wp_nonce_field('pb_add_wallpaper', '_nonce'); ?>
</form>
</div>
<?php
}
add_action('admin_menu', 'pb_wallpaper_adminmenu');
Use
add_action('admin_enqueue_scripts', 'pb_admin_style');
and as the manual states, theadmin_enqueue_scripts
can also be used to target a specific admin page. Use this to only select the admin page you want.This is my load script method , as this i load scripts in specific post type this example is for post_type=’resources’