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
- Lead form that submits to 2 external APIs
- Adding tables to dashboard pages programmatically?
- Setting post_id for single.php based on URL without a redirect
- using admin functions on frontend
- Widget internal hooks and functions
- Javascript Function Called Too Early in PHP Script
- Modify code for functions.php with specific twitter user url and hashtags
- can’t access some WordPress function from my plugin
- WP 3-way voting system: On to something! Please help!
- How to write a shopping queue line plugin with a queue button?
- Custom Settings Plugin Save foreach checkboxes
- 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
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- Can someone explain what’s the use of parse request function in WordPress?
- wp.media gallery collection sometimes undefined
- Get API auth_token token to renew weekly
- Query String Filtering API
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- Add default value from selection
- Rerender core Templates with with ToggleControl but it doesnt recognize block type
- How to query a nested field in wordpress api using _fields param
- function add custom fields to media gallery
- HTMLCollection not counting right in editor? / for loop not working on elements in DOM
- converting a node.js project into a wp plugin
- What happens/fires when you select a block in the editor?
- Is “document loaded” different on admin side than public side?
- Override category archive page title (not the head title)
- How to use setAttributes outside of the edit function return
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- jQueryUI draggable doesn’t work in WordPress plugin
- call funcution when clicking submit
- Make visible page only in the trash
- Reading plugin settings in esnext wordpress block
- Redirection from a specific page for users logged in but not with membership
- WordPress: I wanted to use Add rewrite rule multiple times for multiple CPT in my plugin
- Dynamically modify content added to table via javascript
- Why would one specify multiple arguments when using get_previous_posts_link() which takes only one parameter?
- Adding Amchart Interface to WordPress API
- I cant add is_admin control to plugin
- Load script on frontend from widget plugin
- WordPress Ajax not returning Response
- How do I make secure API calls from my WordPress plugin?
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- Generate Static Page to Show Search Results/Detail for API
- WordPress with React: Saving and Using Data Collected with fetch
- Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework
- Append php file to footer
- XMLHttpRequest to open PHP file responds with Missing Page
- Javascript scroll eventHandler only working when I’m logged in in WordPress
- Replace the WordPress Media Library Uploader
- Remove tag from all posts when publishing new post
- WordPress plugin how to run function when button is clicked
- How to use information from the database in the front-end?
- Using JavaScript in WordPress page to call for server data using AJAX
- wp_ajax add_action fuction won’t fire on custom jQuery action
- Hiding WordPress REST endpoints from public viewing using Basic Authentication
- Pass javascript result to shortcode executer function
- Filterable posts using categories
- add pagination to wp_remote_get
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Add language localisation to javascript alert?
- Multisite and the JSON REST API: How to?
- How do WordPress plugins work with oAuth2 APIs?
- Add function to Dokan ajax class
- Uncaught ReferenceError: kpoejy is not defined
- foreach argument to get specific file types getting too many returns
- How to display archive by selecting year and then selecting month
- Function not working on any file other than the main plugin file
- Building WordPress Themes With Bootstrap with Adi Purdila → TutsPlus
- API WordPress is Limited? Return False
- Ajax not working to insert, query and result data
- Tie specific functions to options-update for limiting API requests
- Do you see any problems (mainly security-related) with how I’ve used wp_ajax_* actions?
- Is there a way to tell if a shorcode’s handler is being run before or after the content formatting filter?
- Template file structure , wordpress hook for altering the template
- WordPress permalink setting
- How can I see a varibles value when my plugin runs?
- Can a plugin differentiate syndication feeds from actual site views?
- How can I add recent posts to menu like mashable
- Why is ‘register_activation_hook’ undefined?
- Developing a plugin, ran it through P3 Profiler, shows up slow, but I don’t know why
- Dynamic banner for use on external sites
- add_rewrite_rule not working
- How can i call from custom fields to the category editor?
- Custom options page for themes
- How do I query posts and have their related taxonomies returned in the results?
- On one of my sites a file is shown as 404 but the file IS there
- Why does this fail: Disabling plugins enqueue_script() in functions.php
- modify buddpress adminbar only in admin pages
- Call do_action() within WordPress cronjob
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- How to plugin function code move to theme function.php ? I’ve tried below code but not working [closed]
- How can i add insertion point between inner blocks in my custom block like core blocks