Load custom script on a single template

Multiple issues, fixing one or more of which should resolve the issue: If it’s not already, that code should go in functions.php and not a template file. Registering the scripts does not actually load them. For that you need wp_enqueue_script. If you change your wp_register_scripts to wp_enqueue_scripts, that should work. If you need jquery, you … Read more

loading a javascript on a WP PAGE

You’ll find a file called functions.php in your theme folder. Open it and add the following snippet: function wpse_109027_enqueue_js() { wp_enqueue_script( ‘custom-script’, get_stylesheet_directory_uri() . “https://wordpress.stackexchange.com/js/script.js”, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, ‘wpse_109027_enqueue_js’ ); wp_enqueue_script is used to add javascript files. The array(‘jquery’) part means that WordPress should load jQuery before loading your javascript file. … Read more

in jquery read a multidimensional array via wp_localize_script()

Accessing the data var data0A = theme_metadata[0].dataA, data0B = theme_metadata[0].dataB, data1A = theme_metadata[1].dataA, data1B = theme_metadata[1].dataB; [Update] Iterating over numeric arrays in JS While the initial question was still somewhat pertinent to WordPress, your follow-up really is a question purely concerning javascript syntax. Anyway, this is how: var dataA, dataB; for ( var i = … Read more

wp_enqueue_script not working?

You could use only one function to do all because it’s the same hook wp_enqueue_scripts: add_action( ‘wp_enqueue_scripts’, ‘my_scripts_method’ ); function my_scripts_method() { //global $wp_styles; //here no use unless you have to use it in a conditional stylesheet for example wp_enqueue_style( ‘twentytwelve-style’, get_stylesheet_uri() ); wp_enqueue_script(‘custom-script’, get_stylesheet_directory_uri() . ‘/js/trans.js’,array( ‘jquery’), null, false ); ); } It’s no … Read more

2nd page displaying the exact same posts as my first page (minus the very first post)

Solution 1 It looks like this might be what is happening to your template: http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query Basically what it’s saying is that the second page doesn’t realize it’s the second page because the “paged” parameter is missing. I’ve just copied directly from the wordpress documentation, which says you should do this: <?php $paged = (get_query_var(‘paged’)) ? … Read more

Using admin-ajax prevents regular php form submission

You can change the form action to admin-ajax.php?action=your_action and this will work, but it’s not best practice. The ajax submition should be added via javascript, not by changing the form action (also your js function should prevent the form from submiting normally, returning false – see here an example: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/), and php handling of the … Read more

Close Fancybox, sumbit form data and redirect

So this is what I did to make it work: <form id=”formid” name=”form” action=”https://wordpress.stackexchange.com/checkout” method=”get”> Text: <input type=”text” name=”text”><br> <a href=”https://wordpress.stackexchange.com/checkout” target=”_parent” onclick=”document.getElementById(‘formid’).submit();”>Finish</a> <input type=”hidden” name=”mess” value=Finish /> </form>