Add Comment Form Shortcode Between Content Area Text

This PHP code enables you to add a small comment form within the content area of a post or page.

You could also use the shortcode this code generates in a text widget if your themes supports shortcodes in widgets.

This code only prints the comment form. If you want to print the entire comment template use the comments_template(); function.

Note: This code uses several output buffering functions starting with the abbreviation ob which you can learn more about on PHP.net. Output control functions enable you to load HTML more efficiently and avoid errors like “headers already sent”.

Here’s an example of what the form looks like within 2 paragraphs of text.

Comment Form Within Text

Here’s some extra code which removes both the comment notes before and after the comment form.

You could reduce the size of the comment content area and remove or re-position some of the comment form fields like this:

inline Comment Form fields

.entry-content .comment-form-author,
.entry-content .comment-form-email,
.entry-content .comment-form-url {
	display: inline-block;
	width: 32.9%;
}

.entry-content .comment-respond,
.entry-content .entry-pings {
	padding: 0;
}

.entry-content .comment-respond input[type="email"],
.entry-content .comment-respond input[type="text"],
.entry-content .comment-respond input[type="url"] {
	width: 98%
}

Similar Solutions


Comments

One response to “Add Comment Form Shortcode Between Content Area Text”

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.