What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?

Completely skipping wp_head and wp_footer doesn’t seem like a good idea, many core components and plugins depend on these hooks. Instead, you could create a light header and footer, and load them via an extra argument to get_header() and get_footer(). get_header( ‘light’ ) will load header-light.php instead of the regular header file. Create one without … Read more

wp_enqueue_script not loading my custom js file

You need to reference your WordPress template directory when you register the script. Change this: wp_enqueue_script(‘my_javascript_file’, ‘/javascripts/app.js’, array(‘jquery’)); …to this: wp_enqueue_script(‘my_javascript_file’, get_template_directory_uri() . ‘/javascripts/app.js’, array(‘jquery’)); Codex reference: get_template_directory_uri()

Fall Back Google CDN in JavaScript

Scripts don’t get printed at the wp_enqueue_scripts hook, but rather at the wp_print_scripts hook. That said: don’t echo/print scripts, period. Instead, enqueue them properly. Caveat: This method is Plugin territory, and should not be included as Theme code in a publicly distributed Theme. You deregister jQuery, but the step you’re missing is registering and enqueueing … Read more

My jQuery is enqueued properly. So why isn’t it working?

jQuery scripts in WordPress require no-conflict wrappers. Instead of this: $(document).ready(function(){ $(#somefunction) … }); Use this: jQuery(document).ready(function($) { // $() will work as an alias for jQuery() inside of this function }); So, in your case: jQuery(document).ready(function($) { $(“#openbtn”).click(function(){ $(“#openingtimes”).toggle(300); }); });

How should I go about registering JavaScript that isn’t a file? [duplicate]

You can hook the wp_footer action to output arbitrary JavaScript. This the same action that WordPress uses to output footer enqueued scripts. Here’s an example that encapsulates the shortcode, data, and script output in a class: <?php /* Plugin Name: WPD_Example */ class WPD_Example_Plugin { public $data = array(); function __construct() { add_shortcode( ‘wpd_example’, array( … Read more