Support » Plugin: Jetpack by » Jetpack contact form not working with do_shortcode()

  • Resolved Chris


    I have encountered the same problem that was raised but not addressed in the thread, Jetpack Contact From not Sending when in do_shortcode.

    Without success, I also tried the solution offered here: Resolved: Jetpack contact form submitting to weird places.

    In the most basic terms, the Jetpack contact form works fine when I insert the shortcode into a post’s or page’s content via the UI text editor. However, if I want to use the Jetpack contact form shortcode in my template files using do_shortcode(), the form appears on the page but no email is sent and no message displays when submitting the form.

    Looking at the contact module code, I happened upon this:

    $form = Grunion_Contact_Form::$last;
    if ( !$form || ( is_wp_error( $form->errors ) && $form->errors->get_error_codes() ) ) {
    // Process the form

    $form is for some reason returning false whenever I use do_shortcode(), so process_submission() never runs. I have tested the same shortcode with do_shortcode() and in the default text editor, so I was able to verify that the shortcode works in the editor but not in do_shortcode(). Does anyone have thoughts on how to solve this problem?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Jeremy Herve


    Jetpack Mechanic 🚀

    You won’t be able to insert forms with do_shortcode, but you can use the following work-around to add Contact forms anywhere in your templates:

    1. Create a new Page, and insert a Contact form in the page.
    2. Note that Page’s ID
    3. In your template, add the following code:
      	query_posts( array( 'page_id' => 123 ) ); // ID of the page including the form
      	if ( have_posts() ) : while ( have_posts() ) : the_post();
      	endwhile; endif;



    Thanks, I have successfully implemented this solution. While testing it I found that the default subject line of the email is now the name of the page where I placed the contact form. Unfortunately I need the subject to remain equal to the post title where this contact form will be displayed; is there a way to do this?

    Previous to updating Jetpack and WordPress to their newest versions, I was using do_shortcode() without any problems. Are there plans to make this usability available again?




    I was able to implement a solution for forcing the subject line to be what I want it to be (in this case, the title of the post on whose template file I am placing the contact form).

    First, hook the custom subject function into the Grunion Contact Form filter:

    add_filter('contact_form_subject', 'product_contact_subject');

    Now, the function:

    function post_contact_subject($subject) {
    	$url = $_SERVER['HTTP_REFERER'];
    	//Create an array divided by the base url. This example assumes that the post slug immediately follows the root domain. Change this to match your permalink structure.
    	$arr = explode(get_site_url() . '/', $url);
    	//Make sure that the array has at least two elements.
    	if (count($arr) < 2)
    		return $subject;
    	//Get the slug and remove the query string and any trailing slash if it exists.
    	$slug = str_replace('/', '', $arr[1]);
    	$slug = preg_replace('/\?.*/', '', $slug);
    	//Get the post id based on the slug.
    	$id = slug_to_id($slug);
    	$title = get_the_title($id);
    	//Return the custom title
    	return $title;

    Now, the function for getting a post’s ID from its slug:

    function slug_to_id($slug, $type = 'post') {
    	  'name' => $slug,
    	  'post_type' => $type,
    	  'post_status' => 'publish',
    	  'showposts' => 1,
    	  'caller_get_posts'=> 1
    	$my_posts = get_posts($args);
    	if( $my_posts ) {
    		return $my_posts[0]->ID;
    	} else {
    		return 0;

    I hope that this helps anybody else with this problem.

    Hi Jeremy and Comrade, I have this problem too. I followed Jeremy’s advice and used a page with a Jetpack form on it. The form still doesn’t seem to be functioning–neither email nor Feedback.

    I have another Jetpack form on a different page which saves in Feedback just fine (no email sent, but I think that’s a server problem).

    Here are the pages in question:

    @tj Kelly – this thread is outdated and already marked resolved. Please start your own thread per the forum guidelines –

    You can do so here:

    Sorry, I didn’t notice the resolved status. Thank you

    Plugin Contributor Ian Dunn


    There’s a patch for this now at

    Plugin Contributor Jeremy Herve


    Jetpack Mechanic 🚀

    The problem was fixed in this commit. We’ll include the fix in the next Jetpack release.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Jetpack contact form not working with do_shortcode()’ is closed to new replies.