I am developing a plugin and using do_action() instead of shortcodes to display plugin content on the site. The plugin will only be used by me, but I am making the plugin to separate components of the site from the theme itself.
How would I go about conditionally displaying javascript and css on a page, IF a specific do_action is called in a theme, from the plugin?
I have found a ton on shortcodes but I wanted to avoid using shortcodes, as I will be calling the actions directly in the theme.
I tried something like this
add_action('wp_footer', 'print_my_script');
function print_my_script() {
if(did_action('my_custom_action')) {
wp_enqueue_scripts('listings');
wp_enqueue_scripts('isotope');
}
}
edit: its wp_enqueue_script() not scripts and changing that solved my problem
but it did not work. I also looked at Scribu's article on the subject for shortcodes and use globals, but that still did not work.
I suspect that I might be able to rearrange priorities and make this work, but I am not sure.
wp_enqueue_script?wp_print_scripts()and changed print to enqueue, and stopped there. thank you! I am in shock that this worked.