I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.

function check_my_login( $atts)

        return '<form action="" name="" method="post" enctype="multipart/form-data">
               <div class="form-group">
                    <label for="description">Project Description</label>
                    <textarea name="p_description" placeholder="Project Description" class="form-control"><?php if (isset($_POST['p_description']) && $_POST['p_description'] != '') echo $_POST['p_description'] ?></textarea>

                <div class="form-group">
                    <label>Project Attachment</label>
                    <input type="file" name="p_attachment">
    add_shortcode( 'kentaUser', 'check_my_login' );

Now use this shortcode inside the Post/page.

Like this

 <div class='manage_page'>[kentaUser]</div>
 But my shortcode content display out side the div.Display upper side in post/page content.
 <div class='manage_page'></div> 

Any one short out this problem.

  • 1
    You are echoing output inside your shortcode. You should not do that. All output needs to be returned Jun 10, 2015 at 10:33
  • any idea for manage this.. Jun 10, 2015 at 10:41
  • Correct this line <textarea>.......</textarea>, your issue is in between those tags Jun 10, 2015 at 10:55
  • Any html code added here display out side of div . I think <textarea> not a issue. Jun 10, 2015 at 10:58
  • 2
    The actual tags in not your issue. Your issue is in that line of code. You are echoing values in between your textarea tags. Please recheck your code properly Jun 10, 2015 at 11:01

2 Answers 2


Use this instead:

Concatenate the html then return it.

function check_my_login( $atts)

    $html = '<form action="" name="" method="post" enctype="multipart/form-data">';
    $html .= '<div class="form-group">';
    $html .= '<label for="description">Project Description</label>';
    $html .= '<textarea name="p_description" placeholder="Project Description" class="form-control">';

    if(isset($_POST['p_description']) && $_POST['p_description'] != ''){
        $html .= $_POST['p_description'];

    $html .= '</textarea>';
    $html .= '</div>';
    $html .= '<div class="form-group">';
    $html .= '<label>Project Attachment</label>';
    $html .= '<input type="file" name="p_attachment">';
    $html .= '</div>';
    $html .= '</form>';

    return $html;

 add_shortcode( 'kentaUser', 'check_my_login' );
  • You don't have to do it this way, you can, as the OP did just return the html, but then it must be done properly. The advantage of your method (which I also use ) is, it is easier to read and cleaner. +1 for your approach :-) Jun 10, 2015 at 11:45
  • It's working... Great......... Jun 17, 2015 at 6:29

If you like me come to this answer because you get this error when using template parts in your shortcode, then I like more the answer from WordPress Core Developer Konstantin Kovshenin to buffer the output:

In your shortcode function:

// start buffer

// call template (with html output)
get_template_part( '/path/to/template/file' );

// return buffered output
return ob_get_clean();

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.