Just hook to wp_enqueue_scripts
for both registering and enqueueing. You’ve registered with in_footer
(last parameter in your code) true
so what you need is:
function print_my_royal_slider_script() {
global $add_my_script;
if ( ! $add_my_script ) return;
wp_enqueue_script('my-script');
}
add_action ('wp_enqueue_scripts', 'print_my_royal_slider_script');
The problem is going to be with $add_my_script
. That has to be set before wp_head
runs. If that is not possible– if, for example, you are setting it in your Loop–, I believe your only choice is to echo the script hooked to wp_footer
but you can (almost) do it properly by using the $wp_scripts
object to do the work.
function print_my_royal_slider_script() {
global $wp_scripts,$add_my_script;
if ( ! $add_my_script ) return;
wp_enqueue_script('my-script');
$wp_scripts->do_item('my-script');
}
add_action ('wp_footer', 'print_my_royal_slider_script');
Related Posts:
- How can i force Display names to be the same as Usernames?
- Adding Custom Fields for Img in Posts
- Edit Imported advanced Custom Fields from wordpress Dashboard
- Add custom meta box on Post page
- how to display all posts Custom fields dynamically?
- add_meta_box Callback not being called
- Custom options page checkbox will not save, despite working with text
- Upload files programmatically to users
- How to create Repeater fields using Advanced Custom Fields?
- Plugin not saving values when placed in a folder within /wp-content/plugins
- Security checking in meta_box save is reluctant?
- Last modified field for user profile?
- WordPress CMB2 – Run function on save
- FacetWP group listings by custom field [closed]
- how do i remove posts from a WP_Query so the pagination is right?
- Carbon Fields use in custom plugin class
- How I can get custom field’s current value?
- UnWanted Custom field added in the wp page edit area
- Woocommerce – How to populate custom select field with stored values on checkout page?
- Implement Autocomplete for a custom field on WordPress Plugin Frontend
- How to query the custom fields by language?
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to toggle between two custom fields in WordPress woocommerce ‘WC Product Field Group’ plugin?
- How do I hide posts across all loops based on the value of a custom field?
- WordPress metaboxes – textfield suggestion automatically populated
- Char limit on custom blog-post form? [closed]
- Unable to select image using custom image field type
- Custom Post Type Fields
- How do I enforce users to fill a determined custom field using WyPiekacz?
- Adding class to last list item? Not WP generated
- How to Resize the Custom Post Images?
- How do we update a custom file upload field with the Advanced Custom Field plugin?
- Order posts by meta key ( Using ACF )
- How to add fields in the WordPress editor?
- WordPress function to add text warning on every pages [closed]
- Price comparison table based on Custom Post Type?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Woocommerce – Change Variable Product Add to Cart to behave like external product using Custom Field (link) [closed]
- Custom Fields for Page Edits
- “After file loaded” action
- Plugin that lets visitors Like a post (not facebook) and stores likes in custom meta?
- grab or load text on demand
- How can I add user profile fields to my mailpress mailout
- Dictionary-style definition list plugin
- Adding custom Field To The Posts Listing
- How to create repeater field manually, without plugin (ACF Pro)?
- Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
- WordPress Phone Field Check (use numbers, spaces and pluses)
- Can export gallery but can’t import it Wp all import
- Table of contents (TOC) plugin is not showing header tag
- Auto populate a user custom field from another user custom field
- Best approach to make all tags searchable by the wordpress search function
- Create a pdf from the entries in DB
- Preset custom fields
- What database state changes happen after a post is manually “updated” with no changes?
- get_post_meta shortcode returns empty field
- custom fields not displaying on wordpress site
- WordPress hide post from custom post-type on a single page
- Create multiple posts when a custom post is created
- Why Custom fields description is not working WordPress Version 5.4.2?
- Adding Custom Endpoint in WordPress Rest API
- General Term for this form Field
- How do I change the functionality of an image slider which is part of ACF?
- Make custom post types using ACF
- Problem Advanced Custom Fields PRO
- How to pass multiple custom fields as shortcode’s parameters
- Get all user meta_keys and then group users by matching values
- Custom product page’s style for printing
- Taxonomy question
- How to get post that has non zero or greater than zero meta value
- Creating Nested custom fields
- Create Biographies
- WordPress doesn’t save a post revision when changing CMB2 custom fields
- How to add wordpress plugins in along with my standalone theme
- Add custom field for users
- How to Save settings of custom tab product page in admin side in a database?
- Changing the body of mail sent to new user registration
- Add new post using a page inside the website
- Creating a user ‘add custom field’ section
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- How can i do custom author list?
- force category table refresh when adding new category
- Is there a way to add a custom input field for every taxonomy term in WP post editor?
- Advanced Custom Fields Plugin – not displaying images
- get_post_meta does not work
- Converting a themes featured image to WordPress featured image
- Woocommerce custom fields
- Trying to use Advanced Custom Fields with custom image sizes
- ACF: Hide a div or template section when a custom field (in a field group) is empty
- How ACF Advanced Custom Field works with Woocommerce Single Product [closed]
- Displaying Random Image from ACF Options Page [closed]
- A plugin for software reviews site like this one?
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- Adding a variable to a meta field in the backend?
- Integrating WordPress Content into a jQuery Slider
- ACF: Not displaying ACF data from another post
- Order shipped by which driver[hook for woocoomerce order staus changed and popup in admin panel ] [closed]
- Outputting custom field query from a plugin to the website header
- Render CMB2 select option to post page [closed]
- Is there a plugin or another way that can help me find out the underlying files of a page/post? [closed]