Use the admin_enqueue_scripts
hook instead of admin_init
Note: you should use hooks that target admin pages as specifically as possible. e.g.:
- Plugins: Use the
admin_print_scripts-{plugin-page}
hook - Themes: Use the
admin_print_scripts-{theme-page}
hook (where{theme-page}
is whatever string you use in theadd_theme_page()
call) - Custom Post-Type Edit Page: Use the
admin_print_scripts-edit.php
hook,
For Custom Post Types, inside your function, do something like the following:
global $typenow;
if( 'portfolio' == $typenow ) {
// wp_enqueue_script() calls go here
}
(h/t t31os)
Related Posts:
- How do I Enqueue styles/scripts on Certain /wp-admin Pages?
- How to disable 3.3 Tooltips?
- Execute script only on certain admin pages
- Enque script based on url paramater
- How to use underscore.js in WordPress Admin
- Trying to get custom js files in my admin header
- load-{$page hook} and returned parameter
- Why is WordPress enqueuing admin relevant scripts (e.g., React, ReactDOM, Redux, hooks, TinyMCE etc) when not logged in?
- How to load Dashboard default media files via HTTPS even when Browser URL has HTTP
- Conditions for admin get_current_screen action parent_file edit.php?post_type=page
- admin_print_styles incuding $_SERVER[‘DOCUMENT_ROOT’]
- How can we make managing lots of pages in WordPress Admin better?
- How to redirect/rewrite all /wp-login requests
- Show all post tags on post edit screen/sidebox
- Add “external” link to admin menu in the backend
- Disable image attachment links
- Remove “Time to upgrade” message from dashboard
- How can I enable Google Analytics on a file download link?
- What is the best method to close off the backend?
- Change Login URL Without Plugin
- Adding a menu item in the admin bar
- how to force caching of wordpress admin
- Slow admin – waits and is blocked for a long time
- “leftover” notifications left on ever admin screen?
- Excerpt textarea missing on post editing page in admin panel
- wp login redirects to homepage
- Dashboard links not working
- jquery UI in wordpress admin
- Resize Admin Featured Image Thumbnail in CPT Edit Screen
- Displaying which Role the current user is assigned to
- Restrict access in wp-admin area?
- Retrieve Path of admin.php
- Adding HTML/Text to Top of Subscriber’s Profile Backend Page
- submit for review issue
- wp-admin does not redirect to dashboard
- Display $pagenow error notice on all admin pages
- Change WP-Login or WP-Admin
- Custom roles showing HTML entities in title form field
- WordPress address URL keeps dropping the www
- How to show postmeta in custom columns for the posts screen?
- disable a wp javascript on live website, but not on wp-admin page
- How can I remove the user avatar from admin toolbar?
- How to stop – Database Update Required – from happening again?
- using wp_sprintf at wordpress option page,
- Can’t login to Dashboard when changing site URL to HTTPS
- Limit access to wp_admin
- Not Found (404) error on admin page, CSS gone on blog
- Remove All in One Pack from the admin bar
- Disable wordpress reordering functions in backend screen element
- transition_post_status not working via Quick Edit
- WordPress server change – slow admin login time for first time
- I can´t access my admin panel. I tried all possible solutions
- Ajax solution similar to WP Categories functioning in Admin area
- Difference between admin and user admin
- Hooks: admin_footer and admin_print_footer_scripts not working?
- Editing edit-tags.php page in wp-admin
- What is the correct way to get only display plugin for Administrator Only
- displaying an error before update_post_meta
- Browse Happy in 3.2
- Adding Notification Bubble on Admin Top Bar
- Outputting something based on the presence of post variable in admin screens
- Use of domain name
- “Add New” button on custom post type grid
- Where is function to prevents non logged users access wp-admin?
- WordPress site stopped working after simply opening header.php in the wp-admin editor
- CSS of the admin panel
- Ajax requests from front-end with jQuery Fancybox
- Dismiss Admin Pointer Temporarily
- WordPress admin right sidebar isn’t working
- WordPress menu to change page title
- wp-admin blocking causing http error on uploads
- Performance-issue in WP-admin with a lot of posts
- Disable some features in Admin
- DISALLOW_FILE_EDIT is false but I still am not able to edit files from the admin interface and the menus do not show up
- Don’t run code if in customizer or privew
- What hooks should you use to create a table only once?
- Redirect WordPress login for customers but not admin
- Cant access wp-admin
- Unable to open specific posts on WP Dashboard [duplicate]
- How to list newly ftp added HTML webpage under Pages section of wp-admin?
- Hi everyone, I have Problem with using wp_die()
- WordPress wp-admin Page
- How can I trigger a javascript function after a post update on edit post screen in wordpress admin panel?
- restrict admin panel sections to users
- how to set not to be logined in wp-admin except administrator?
- Disable flyout (popup) menus in backend
- WordPress, content editor default type
- Random HTTPs redirections at admin area in shared hosting
- WordPress Login for multiple sites
- Blank sign in page
- add_post_meta displays in admin edit area
- Forcing WordPress Administration onto a separate SSL Host
- How to prevent Google adsense invalid impressions while performing admin tasks on my wordpress site?
- Action for opening edit page in admin?
- What is the point of new confirm admin email process?
- ‘Too many redirects’ error after changing site URL in WordPress [closed]
- Is it possible to tell if a user is logged into WordPress from looking at the cookies which are set?
- Redirecting the user to the admin table area after publishing a post, getting an invalid response error?
- How can you change the admin dashboard URL without symlinking?
- Degraded WordPress admin dashboard performance [closed]