USP Pro provides a Content field through which users can submit post content along with the post title, tags, and other information. By default, this field is displayed to the user without any predefined content, which is ideal for most cases. But if you want to include some default content, that also is possible using some custom code. This tutorial explains a couple of ways of making it happen.

Add default content via shortcode

An easy way to add custom/default content to the Post Content field (i.e., the field added via [usp_content]) is to create a shortcode that users can add manually to the form. For example, here is a simple shortcode that displays a message and some basic markup:

// usp pro add default post content
function usp_pro_example_shortcode($atts) {
	
	// replace this with the code you want to display
	
	$output = '<p><strong>Add your custom code here</strong></p>';

	return $output;
}
add_shortcode('usp_pro_example_shortcode', 'usp_pro_example_shortcode');

After including this code in your theme’s functions.php, the contents of the $output variable will be displayed wherever the shortcode, [usp_pro_example_shortcode] is included. So if this shortcode is added to your form’s Post Content field before submitting the form, the post will display the output on the frontend of your site.

Pros of this method:

  • Easy to implement
  • Easy to customize with any custom content
  • Displays the output automatically on the frontend
  • You can update the shortcode output at anytime

Cons of this method:

  • Requires the user to manually add the shortcode to the Post Content field
  • The shortcode output is not displayed in the Post Content field, it’s only displayed on the front-end

If this method works for you, then great. If not, most likely it’s because of the two cons mentioned above. If that’s the case, no worries, there is another way of going about it..

Add default content via JavaScript

If the shortcode method doesn’t meet your needs, you can add any default/custom content via a bit of jQuery. For example, let’s say that we want to pre-fill the content area with a paragraph of text. To do so, we can add the following code snippet:

<script>
	jQuery(document).ready(function($) {
		var content = '<p>Lorem ipsum blah blah blah..</p>';
		$('#usp-content').append(content.replace(/\&/g, '&').replace(/</g, '<').replace(/>/g, '>'));   
	});
</script>

This snippet requires that jQuery be included on the page. To change the text/markup that is displayed, edit the <p>Lorem ipsum blah blah blah..</p> with whatever you require. Once in place, this code will display the specified content within the form’s Post Content field (i.e., within the field displayed via [usp_content]).

Important: by default, USP Pro disables any markup in the Post Content field. So, to enable the markup that you want to include, visit the Advanced ▸ Post Formatting settings and enable enable Post Formatting.

Pros of this method:

  • Easy to implement
  • Easy to customize with any custom content
  • Displays the output automatically on the frontend
  • Displays the output automatically in the Post Content field
  • Displays the output automatically in the Admin Area on the Edit Post screen

Cons of this method:

  • Requires JavaScript in order to work
  • The user can modify/delete the output before submitting the form

And of course, the best way to compare the two techniques described above is to try them out for yourself.

Add default content via the plugin settings

Last but not least, there is a USP Pro setting that enables you to define a default Post Title and Content. So check that tutorial for more information.

Related