Jetpack processes shortcodes twice?
-
It seems that after activating Jetpack, WP shortcodes are processed twice. Once as part of the wp_head() execution (unexpected) and once in the loop (as expected).
I suspect this is because of an additional do_shortcode() call in one of the Jetpack actions.
Can this be resolved or is there a way to avoid shortcodes to be triggered inside the header?
-
Can you provide an example of where this is happening?
Also, is there a specific plugin that this happens with?
It’s been happening with one of our plugins, the Bookings plugin and reported by a couple of our users.
It can be replicated with the following code:add_shortcode( 'bookings', 'bookings_shortcode' ); function bookings_shortcode( $atts, $content=null, $code="" ) { return 'test'; }
In this case ‘test’ will be output in the header and on the page.
Note that the above is an abreviated version of the code used in the Bookings plugin.Thanks for the info; we are looking into this issue.
I’m unable to reproduce this using Jetpack 2.1.1 and latest WordPress.
Are you by chance using
get_the_excerpt
orget_the_content
orthe_excerpt
orthe_content
actions in your plugin?No, not using any of those. Maybe it’s caused by a combination of Jetpack with another plugin. The person who reported the issue managed to resolve it by disabling Jetpack.
It’s possible. If you want to have the person who reported the issue contact us directly, our email address is support@jetpack.me. We’d be happy to help resolve this and get whatever fix in place that is necessary. I just need some more debugging info to go in first 🙂
Thanks!
OK, thanks for your help so far. I will let the person know.
I have this problem too. I placed a PHP warning and got a stack trace. Here’s how JetPack is calling the shortcode:
PHP Stack trace:
PHP 1. {main}() /mywebsite/index.php:0
PHP 2. require() /mywebsite/index.php:17
PHP 3. require_once() /mywebsite/wp-blog-header.php:16
PHP 4. include() /mywebsite/wp-includes/template-loader.php:43
PHP 5. get_header() /mywebsite/wp-content/themes/cloudhost-parent/page.php:4
PHP 6. locate_template() /mywebsite/wp-includes/general-template.php:34
PHP 7. load_template() /mywebsite/wp-includes/template.php:366
PHP 8. require_once() /mywebsite/wp-includes/template.php:390
PHP 9. wp_head() /mywebsite/wp-content/themes/cloudhost-child/header.php:33
PHP 10. do_action() /mywebsite/wp-includes/general-template.php:1576
PHP 11. call_user_func_array() /mywebsite/wp-includes/plugin.php:403
PHP 12. jetpack_og_tags() /mywebsite/wp-includes/plugin.php:403
PHP 13. jetpack_og_get_image() /mywebsite/wp-content/plugins/jetpack/functions.opengraph.php:71
PHP 14. Jetpack_PostImages::get_images() /mywebsite/wp-content/plugins/jetpack/functions.opengraph.php:109
PHP 15. Jetpack_PostImages::from_html() /mywebsite/wp-content/plugins/jetpack/class.jetpack-post-images.php:407
PHP 16. apply_filters() /mywebsite/wp-content/plugins/jetpack/class.jetpack-post-images.php:254
PHP 17. call_user_func_array() /mywebsite/wp-includes/plugin.php:170
PHP 18. do_shortcode() /mywebsite/wp-includes/plugin.php:170The shortcode then gets called a second time in the ordinary way:
PHP Stack trace:
PHP 1. {main}() /mywebsite/index.php:0
PHP 2. require() /mywebsite/index.php:17
PHP 3. require_once() /mywebsite/wp-blog-header.php:16
PHP 4. include() /mywebsite/wp-includes/template-loader.php:43
PHP 2. require() /mywebsite/index.php:17
PHP 3. require_once() /mywebsite/wp-blog-header.php:16
PHP 4. include() /mywebsite/wp-includes/template-loader.php:43
PHP 5. the_content() /mywebsite/wp-content/themes/cloudhost-parent/page.php:26
PHP 6. apply_filters() /mywebsite/wp-includes/post-template.php:166
PHP 6. apply_filters() /mywebsite/wp-includes/post-template.php:166
PHP 7. call_user_func_array() /mywebsite/wp-includes/plugin.php:170
PHP 8. do_shortcode() /mywebsite/wp-includes/plugin.php:170This caused me a big problem, as the shortcode was processing _POST parameters – twice.
P.S. Disabling Photonic only (not the rest of JetPack) removed the double-call.
I spoke too soon – the error has returned, even whilst Photonic is off.
Thanks David, hopefully this gives Tim more info in order to resolve the issue.
Is there any updates on this. I have this problem on my live site. Is their a temporary work around, other than disabling it?
I’ll take a look at this and get a fix out as soon as I can.
This is also happening to a theme forest theme I’m using called Natural. The galleria shortcode is broken by this same issue. I hope you guys find a workaround quickly. I want to use both Jetpack and galleria.
Confirmed this happening with my plugin sp client document manager plugin as well. It seems to be running the shortcode once before the document and once again in the document.
- The topic ‘Jetpack processes shortcodes twice?’ is closed to new replies.