Call javascript functions from each page

I would create a custom field containing the function to be called, for example called ‘function_to_call’. In the templatefile add the code $function_to_call = get_post_meta( get_the_ID(), ‘function_to_call’, true ); if ( $function_to_call != “” ) { echo ‘ jQuery(document).ready(function($){ ‘ . $function_to_call . ‘() }); ‘; } Doing this only outputs the function if you … Read more

JS Plugin not executing the js correctly. Trying to make all internal links scroll smoothly

Save your JavaScript code out to a separate file within your plugin directory. Then use this code to load the file using the wp_enqueue_script() function. function smooth_scrolling_links() { if ( !is_admin() ) { // Don’t load if in the admin screen wp_enqueue_script(‘Smooth-Scolling-Links’, plugin_dir_url(__FILE__) .’-YOURFILENAME-.js’); } } Obviously replace the -YOURFILENAME- with the file name that … Read more

How to add a onclick attribute to a list of checkboxes?

Store the ID in a variable, and access that variable using JavaScript: <script> document.getElementById(“<?php echo $checkbox_id; ?>”).onclick = function() { chk(electronics, this.checked); } </script> You can also collect multiple IDs in an array and run through that array later in your script. But avoid the onclick attribute in markup, this is bloat and bad code … Read more

Is there some jQuery conflict here?

If I click on the large button on the bottom of your page (the one in your first screenshot), then your page is called with the parameter ?paged=2. If I call your page directly with this parameter, I got the following JS error TypeError: $ is not a function From the source of your page: … Read more

How to setup a popup registeration page in wordpress with function.php

You can add the HTML for the area via wp_footer, include the style with wp_enqueue_style(), and include the javascript to show/hide the popup with wp_enqueue_script(). wpse90382_popup_function() { add_action( ‘wp_footer’, ‘wpse90382_popup_html’ ); wp_enqueue_style( ‘your_style’, get_template_directory_uri() . ‘your_stylesheet.css’ ); wp_enqueue_script( ‘your_script’, get_template_directory_uri() . ‘your_javascript.js’ ); } wpse90382_popup_html() { ?> <div>Your HTML</div> <?php } if ( some condition … Read more