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);



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 )
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.

  • I use same solution, as shows there. – kafaya Jan 17 '14 at 14:07
  • 1
    I tested your code with a simple, generic shortcode, and it works fine, except for a missing } which I assume is just a typo. So this is not a generic shortcode issue. It has something to do with the way the Contact Form 7 shortcode(s) work, though I can't spot what. That is a lot of code to dig through. – s_ha_dum Jan 17 '14 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.