Posted by & filed under Lessons Learned.

We love using Jetpack contact forms because they filter through the fantastic spam catcher, Askimet, are easy to configure, and get saved into the Feedbacks Tab. All good.

But we did run into a very strange problem with them when we embedded them into a template with do_shortcode()

Jetpack contact forms are made to automatically figure out where they are being displayed, usually in a post or within page content. It does this by looking at the global $post variable, assuming that the form appears within the WordPress loop.

This doesn’t work quite as expected when we include the Jetpack contact form directly in a template using do_shortcode().

Why, you might ask? Well, because the global $post may have been filled by any other loop also on the page. In this case, it was repopulated with a blog feed!

The Solution

Right before your do_shortcode() call in the template, place a wp_reset_query(). This resets the global $post back to what it should be, and everything works!


Leave a Reply

  • (will not be published)