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.phphook,
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’]
- Changing Admin Menu Labels
- How to add a custom metabox to the Menu Management admin screen?
- How to remove items from +New admin menu?
- remove plugin admin menu in wordpress without installing plugin in v3.8.1
- Only allow administrators and editors to access wp-admin
- Create a admin page in wordpress without admin menus (“wordpress sidebars”)
- New wordpress install, what are the reasons the “Install Themes” tab is missing?
- Customise WordPress Update Notice in wp-admin backend area
- I get a 404 page on /wp-admin but not wp-login but as soon as I login I get a 404 again [closed]
- I want to disable login of admin (/wp-admin) with email and make it accessible only with username
- Post.php is blocked by server? How to unblock? [closed]
- WP-Admin shows (1) update but there is no update for plugin, theme or WordPress
- Register page in admin area
- Downgrade admin account by mistake
- Deploying WordPress for clients – what do they have access to?
- Removing Dashboard Menu Items Through The Database
- “WordPress installations is currently out of date” problem with difficult situation [closed]
- Can’t access wp-admin, redirects to http://%24domain/wp-admin/
- Can log as admin but dashboard missing [closed]
- Custom plugin admin page issues
- Making Comments, a sub_menu in admin menu
- Without using wordpress cms Is it possible to signup from my html page
- Customising Word press Admin – Add Post Page functionality to another similar page
- How to add ‘Insert HTML Table’ button to TinyMCE in admin?
- How to allow WordPress updates to only one specific administrator?
- How can I remove commas when adding tags?
- Displaying Title in Title Tag on Edit page?
- How to add custom CSS and JavaScript file for wp- admin dashboard (backend)
- GoDaddy hosting wp-admin problem
- Cannot change Connection Information in admin interface
- How can I remove unwanted word on my WP site?
- Add custom fields to a page template, admin side
- Error messages & can’t reach admin after upgrading to 3.4.1 WordPress
- WordPress blog clone.. wp-admin issue
- How to take the help button and link off the dashboard
- Newly created user role not displaying on users screen
- Could not override the url in wp-config file
- How do I fix wp-admin error when exporting reusable blocks?
- issue with wordpress [wp-admin] redirects, when using kubernetes ingress hosting two wordpress websites using path
- Toggle between block ‘edit content’ and ‘select’ not properly working in WordPress Admin
- WordPress Admin extremely slow when other admin logged in
- Can’t acces login on new site
- WordPress Admin Panel Left Sidebar No showing on Post create page
- WordPress Migration Post Problems
- How to remove the color picker code from users-edit.php
- wp-config.php not affecting my site
- How to prevent spams from admin-ajax.php file?
- After changing Site http to https, can’t access wp login page with a digitalocean hosting
- Can’t access WP-Admin via HTTPS
- wp-admin and wp-login.php not Accessible after Cloudflare
- Strange wp-admin problem for all users/adminstrators except the original one?
- Get rendered HTML of Page in Admin Area
- Having SSL enabled on admin, but disabled on post preview and live preview?
- adding existing menu page on new customer user role
- stop customize.php redirect to login page if admin is not logged in
- Random authentication failures on a load balanced WP setup
- Can I get programmatic access to wp-admin?
- Strange URLs admin area bug
- remove_query_arg on options.php
- wp.svgPainter cannot init error, causing issues with admin panel
- mysql_escape_string PROBLEM
- Cannot access my wordpress website
- Google flagged a wp-admin redirect as phishing
- Organising and display thousands of photos in media library
- Custom comment action
- Problem with admin columns
- Checkbox not showing as checked on UserProfile (even with checked=”checked”)
- Get URL of current featured image with JS in edit post view
- get_current_screen – ‘Trying to get property of non-object’ error
- Added fields in quick edit screen need to update at the moment
- Custome column sort by date not title
- Block tools menu in wp-admin?
- is_admin() triggers error
- WordPress Admin: open popup window on a custom button
- Modify admin panel tab position
- No HTML/Visual mode option in admin panel (New Post)
- Removing Author name
- not able to add thumbnail custom field in dropdown
- No wp-admin, wp-config, or .htaccess folder/file
- Taking over a WordPress site
- WordPress blog fails to open
- wordpress admin is broken [closed]
- LinkControl not showing suggestions when used on admin page
- Override WordPress Core File?
- WordPress Users page missing user count next to different types of users
- Not receiving verification email to update administrator email in wordpress
- contact form 7 form not working in admin panel
- Is there a way to get the WP Admin Header to inject as the first element in the body instead of the last?
- Creating an custom admin page from scratch