Suggested fix for page/post JS not loading
-
Here is the fix I’ve been using to get custom page/post JS to load. In spcc_class.php, add the following to the end of the constructor, line 20:
add_action('wp_footer', array($this, 'spcc_single_custom_js'));
Then add the following function to the end of the file, right below spcc_single_custom_css:
public function spcc_single_custom_js() { if (is_single() || is_page()) { global $post; $single_custom_js = get_post_meta($post->ID, '_single_add_custom_js', true); if ($single_custom_js !== '') { $output = "<script>\n" . $single_custom_js . "\n</script>\n"; echo $output; } } }
It’s basically a mirror of the code that loads the CSS, only it outputs the JS instead. Works great for me.
Thank you for creating this super useful plugin!
- The topic ‘Suggested fix for page/post JS not loading’ is closed to new replies.