How to load wordpress sidebar using AJAX [duplicate]

Just go ahead and use a CSS media query to set the sidebar to display: none if the screen is too small, and provide your mobile users with some JavaScript that lets them selectively view it if they want to. Don’t worry about the loss in bit-and-cycle efficiency this causes; assuming that you get no … Read more

Closing ajax function file with die() causes error and empty page

The die should be in your show_article() function. Yours is out, so the whole script is terminated. Your function should be: function show_article(){ $q = $_GET[‘getid’]; echo strval($q); die; } or function show_article(){ $q = $_GET[‘getid’]; exit( strval($q) ); }

wp_localize_script not create variable in head section

Your code looks correct. alert(wp_ajax.nonce); should display the nonce. You can also verify the existence of the wp_ajax object via console.log(wp_ajax) in your browser’s Javascript console. wp_localize_script adds the object(s) to the footer (a call to wp_footer() should be present in the theme’s footer.php file). It’ll look like so: <script type=”text/javascript”> /* <![CDATA[ */ var … Read more

Ajax Form seems to post, but does not return

Your settings object in ajax call is not properly set up: action should be inserted in the data object. For example: $.ajax({ url: ajax_url, data:{ action: ‘trailer_report’,// action must be set here // other stuff here } //other ajax stuff }); Hope it helps!

Ajax navigation and scripts loaded only on certain pages

If the plugins are nice about it and register all of their scripts upfront, and then just enqueue them as needed, you should be able to enqueue all of them to load all the time. Find out the handles they were registered with and enqueue them. add_action(‘wp_enqueue_script’, function() { wp_enqueue_script(‘example-handle’); wp_enqueue_script(‘another-example-handle’); }, 20); However, some … Read more