Loading shortcode with ajax

You cannot load a file directly like this: $(‘.homepage__slider’).load(‘wp-content/themes/mytheme/slider.php’); Also note that WordPress loads jQuery in noConflict mode, so the $ alias does not work. If you load a file directly none of the WordPress functions will work. You should be using the AJAX API so that everything loads in WordPress context. You would wrap … Read more

do_shortcode inside AJAX callback

The How It would be much better and easier if you’d just add the script directly to the main body instead of the AJAX call. The same goes with the shortcode result. Just use the shortcode as argument inside wp_localize_script(): wp_localize_script( ‘script-handle’, ‘pluginObject’, array( ‘contactForm’ => do_shortcode( ‘[contact-form-7 id=”698″ title=”Meet The Team Email”]’ ), ) … Read more

How to filter post data with AJAX on page?

As you guess that’s what happening(at least I think). You should separate your ajax logic from your “first load” logic. You can make a function ie my_get_posts that will be called inside archive-work.php and then inside ajax_filter_get_posts you can call the my_get_posts() function. archive-work.php <div class=”work-results”> <?php $res = my_get_posts(); echo $res[‘response’]; ?> </div> functions.php … Read more

WordPress embeds in AJAX inserted content

I think the solution is amazingly simple here: You’re just missing a single line of code in your ajax callback, namely: global $post; where I assume you’re using: $post = get_post( $post_id ); The reason is that there’s a global post check in the WP_Embed::shortcode() method. More details in my answer here.

Load categories with ajax

The error says it all, you are sending the request to a invalid host. Change this: var ajaxurl=”http://my-site.co.uk <?php bloginfo(“wpurl”);?>/wp-admin/admin-ajax.php”; To: var ajaxurl = “<?php echo esc_js( admin_url( ‘admin-ajax.php’ ) ) ?>”; Note: from your code and description I’m assuming you are generating the jQuery code within PHP and it is not in a js … Read more

How to get Ajax into a theme – without writing a plugin?

Put those add_action functions in your functions.php file too. If they’re in header.php, WordPress never registers them since header isn’t loaded in AJAX. Also, you don’t need that is_admin() check. The theme’s header will never load in admin. So, your functions file should look like this: add_action(‘wp_ajax_my_special_action’, ‘my_action_callback’); add_action(‘wp_ajax_nopriv_my_special_action’, ‘my_action_callback’); function my_action_callback() { $whatever = … Read more