How to pass code from header.php to footer.php

Avoid global variables, they could be overwritten by other code. You could use a helper function with a static internal variable instead. Sample code: function wpse_69365_var_storage( $var = NULL ) { static $internal; if ( NULL !== $var ) { $internal = $var; } return $internal; } // first call: wpse_69365_var_storage( 4 ); // later … Read more

Using AJAX to return search form results

There are two issues in your code You need to add script in wp_enqueue_scripts hooks like this – add_action(‘wp_enqueue_scripts’, ‘my_custom_js_script’); function my_custom_js_script() { wp_register_script( ‘ajax-productSearch’, get_template_directory_uri() .’/js/ajax-product-search.js’, array( ‘jquery’) ); wp_enqueue_script( ‘ajax-productSearch’ ); wp_localize_script( ‘ajax-productSearch’,’the_ajax_productSearch’, array(‘ajaxurl_productSearch’ => admin_url(‘admin-ajax.php’))); } The second issue is that, you need to add action argument in your jQuery.ajax data. If … Read more