I try to call contact-form-7 via ajax with do_shortcode. But it shows just “shortcode code”.
function example_ajax_request() {
// The $_REQUEST contains all the data sent via ajax
if ( isset($_REQUEST) ) {
$shortcode = do_shortcode("[contact-form-7 id='900' title='Email Us']");
echo apply_filters('the_content', $shortcode);
die;
}
add_action( 'wp_ajax_example_ajax_request', 'example_ajax_request' );
add_action( 'wp_ajax_nopriv_example_ajax_request', 'example_ajax_request' );
add_action( 'init', create_function('', 'register_shortcode_ajax( "example_ajax_request", "example_ajax_request" ); '));
function register_shortcode_ajax( $callable, $action ) {
if ( empty( $_GET['action'] ) || $_GET['action'] != $action )
return;
call_user_func( $callable );
}
I check it with suteurl/wp-admin/admin-ajax.php?action=example_ajax_request&ajax=true&width=600&height=300 and see [contact-form-7 id=’900′ title=’Email Us’] content.