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>
<div class="form-group">
<label>Project Attachment</label>
<input type="file" name="p_attachment">
</div>
</form>';
}
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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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' );
Method 2
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 ob_start(); // call template (with html output) get_template_part( '/path/to/template/file' ); // return buffered output return ob_get_clean();
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0