The way to do this is to use the ‘admin_enqueue_scripts’ hook to en-queue the files you need. This hook will get passed a $hook_suffix that relates to the current page that is loaded:
function my_admin_enqueue($hook_suffix) {
if($hook_suffix == 'appearance_page_theme-options') {
wp_enqueue_script('my-theme-settings', get_template_directory_uri() . '/js/theme-settings.js', array('jquery'));
wp_enqueue_style('my-theme-settings', get_template_directory_uri() . '/styles/theme-settings.css');
?>
<script type="text/javascript">
//<![CDATA[
var template_directory = '<?php echo get_template_directory_uri() ?>';
//]]>
</script>
<?php
}
}
add_action('admin_enqueue_scripts', 'my_admin_enqueue');
Related Posts:
- Remove from a div by class name from post page if post author role is not administrator
- How to include PHP files in plugins the correct way
- Difference Between Filter and Action Hooks?
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How to create an API for my plugin?
- What is an alternative method to the WordPress private _doing_it_wrong() function
- Can I use the wp media uploader for my own plugin?
- Customizing the 3.5 “Add Media” popup (Backbone.js)
- Using filters and actions for plugin API?
- Using OOP plugin’s methods throughout the website
- WordPress and multithreading
- Hook the Keydown Event in the TinyMCE Post Editor
- permalinks with get variables
- function triggered by “manage_users_custom_column” filter not working
- WordPress plugin how to run function when button is clicked
- lodash dependency in a Gutenberg plugin
- Shortcodes, output buffering, and WordPress functions
- Determine which theme location a wp_get_nav_menu_items is for
- When to check if a function exists
- Checking for existence of a page by title?
- How do I only load js on the post-new.php and post.php pages in admin?
- creating elements/innerblocks via rangecontrol
- What is the difference between current_page_parent and current_page_ancestor?
- Does add_filter work outside functions.php
- What function to hook for changes made in status and visibility of a post
- Can’t get JS code to work with shortcode
- Should I ask my Twitter plugin users to create their own Twitter App and API Keys to use my plugin?
- how to use preg_replace for wordpress video?
- How do I add a javascript file to all admin pages via a plugin?
- Gutenberg – What is the best way to save/update post meta?
- How to Load Plugin JS in theme’s footer section
- wp_enqueue_script + wp_enqueue_style Since When
- $content variable – Is this a reserved variable for a WordPress function? – php / wordpress
- WordPress after content Hook & external template part
- Retrieve contents/page names of various pages for use in a plugin
- Can wp_list_comments output into variable?
- Can I change header.php of current theme through a plugin function?
- get_current_screen() return null
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- How to change the hover content of a specific menu item on WordPress?
- Amending REST API function without deactivate/activate plugin every time changes is made
- Why does wp_remote_post returns an empty body response on certain endpoints?
- Sending post request with wp_remote_post not working correctly
- Gutenberg: import dependency or assign from global variable?
- How do I update a field of a meta box?
- add javascript files only when plugin is called?
- WordPress function get_the_terms() returns ‘Invalid taxonomy’ error
- What to hook into to check a value before a post is published?
- wp_get_theme Warning: Illegal offset type
- Print Dashboard submenu name and filename
- Run JavaScript validation script on form submit in plugin
- Custom Plugin – CSS works, JS doesn’t
- Apply styles to blockquote element with the WYSIWYG editor
- Google credentials and redirect URI for Google OAuth2 in a WordPress plugin, questions
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Service Worker Uncaught (in promise) DOMException
- Plugin index page code executes multiple times
- Pass CF7 form data to plugin
- How to output functions from plugin inside theme
- About a programming language starts with [closed]
- Should I put my plugin javascript inline?
- Plugin architecture to pull from API & create dynamic content on WP site?
- Remove Permalink Meta Box not working?
- Lead form that submits to 2 external APIs
- Modify code for functions.php with specific twitter user url and hashtags
- can’t access some WordPress function from my plugin
- Customise Grouped Product display in Woocommerce with custom column
- Change the behaviour of a button
- wp.media libary pdf type
- Allow REST API Endpoint to specific user and hide from public
- Can someone explain what’s the use of parse request function in WordPress?
- Get API auth_token token to renew weekly
- Query String Filtering API
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- Add default value from selection
- Override category archive page title (not the head title)
- jQueryUI draggable doesn’t work in WordPress plugin
- call funcution when clicking submit
- Redirection from a specific page for users logged in but not with membership
- Why would one specify multiple arguments when using get_previous_posts_link() which takes only one parameter?
- I cant add is_admin control to plugin
- Load script on frontend from widget plugin
- How do I make secure API calls from my WordPress plugin?
- Generate Static Page to Show Search Results/Detail for API
- Append php file to footer
- XMLHttpRequest to open PHP file responds with Missing Page
- wp_ajax add_action fuction won’t fire on custom jQuery action
- Hiding WordPress REST endpoints from public viewing using Basic Authentication
- Filterable posts using categories
- Add function to Dokan ajax class
- Function not working on any file other than the main plugin file
- Building WordPress Themes With Bootstrap with Adi Purdila → TutsPlus
- How can I see a varibles value when my plugin runs?
- Can a plugin differentiate syndication feeds from actual site views?
- get_term_by() returning null on plugin
- How can create a custom plugin to call my webapi after any registration or membership plugin functionality
- Programmatically creating posts based on external JSON feed (asynchronously)
- Trouble Importing whatsapp-web.js in a WordPress Plugin Development
- Reinitiate Gutenburg’s blocks using javascript
- how to add contact form 7 shortcode in javascript variable