0

I've added a shortcode [form] inside my wysiwyg the 2 paragraphes before the shortcode.

<p>test 1</p>

<p>test2</p>

[form]

but on the frontend, the shortcode is showing at the top of the content. I thought it was an error in CSS, but the HTML is indead rendering the form, and then my paragraph.

Any idea? I'm on WP 5.4

EDIT :

This is how the shortcode is created :

/* SHORTCODE */
function form_shortcode() {
    include( "includes/form.php" );
    return;
}

add_shortcode( 'form_calcul', 'form_shortcode' );

I have a few lines of php inside. I should probably precise, I'm in a plugin. I tried also this, but no success:

    ob_start();
get_template_part('form');
return ob_get_clean();
3
  • Obviously, this depends on what the shortcode does, but since you didn't include its code, it's impossible to tell.
    – cjbj
    Commented May 13, 2020 at 8:07
  • 3
    Does this answer your question? Shortcode outputs at the top of the_content Commented May 13, 2020 at 8:10
  • The shortcode is showing a form surounded by a div
    – Morgan
    Commented May 13, 2020 at 8:15

1 Answer 1

0

Before the_content is displayed WP looks for filters to run the content through. One of those filters is do_shortcode. The idea of a filter is that you can change something before it is displayed. As a consequence, if inside the filter function you echo something, it ends up before the_content, which is still waiting for the filtering process to be completed.

Since your function form_shortcode() does not return a modified content anything that is displayed must be the result of echo statements in form.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.