WP Mayor is supported by its audience. Our recommendations are based on our experts’ research and hands-on testing. If you purchase through a link on our website, we may earn a commission. Here’s why you can trust us.

Add Default Content to New Posts

  Introduction
With WordPress hooks you can easily add default content to new posts, if you are repeatedly entering some content into all your posts this is a great productivity aid. Learn how...
WP Mayor is supported by its audience. Our recommendations are based on our experts’ research and hands-on testing. If you purchase through a link on our website, we may earn a commission. Here’s why you can trust us.
 Table of contents

With WordPress hooks you can easily add default content to new posts, if you are repeatedly entering some content into all your posts this is a great productivity aid. Just insert the following into your functions.php file, editing the value of the $content variable to reflect the message you want to insert into new posts.

[php]
add_filter(‘default_content’, ‘my_editor_content’);

function my_editor_content( $content ) {
$content = "If you enjoyed this post, make sure to subscribe to my rss feed.<br>This goes on the second line";
return $content;
}
[/php]

You can also use conditionals to apply this to specific post types:

[php]

add_filter(‘default_content’, ‘my_editor_content’);

function my_editor_content( $content ) {
global $post_type;
if ( ‘post’ == $post_type ) {
$content = "If you enjoyed this post, make sure to <a href="http://feeds.feedburner.com/WPMayor">subscribe to WPMayor’s RSS feed</a>.";
return $content;
}
}

[/php]

If you enjoyed this post, make sure to subscribe to my rss feed.

Jean Galea
Jean Galea
Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.
Recommended For You
Recommended For You
Get more expert advice like this delivered to your inbox every week.
Join thousands of designers, developers, and marketers who trust our experts to find and test the best tools and services for your website.
By signing up to our newsletter, you agree to receive electronic communications from WP Mayor that may include advertisements.
Get more expert advice like this delivered to your inbox every week.
Join thousands of designers, developers and marketers who trust our experts to find and test the best tools to build, improve, and optimize their websites.
By signing up to our newsletter, you agree to receive electronic communications from WP Mayor that may include advertisements.
Join the Conversation

5 Responses

  1. If you want to automatically add specific default or pre-defined content to your editor while publishing posts or pages, then insert one of the following codes into functions.php:

    1)
    function add_before_content($content) {
    if ( ‘page’ == $post->post_type ) return $content .’Default page content.’;
    if ( ‘post’ == $post->post_type ) return $content .’Default post content.’;
    }
    add_filter(‘the_content’, add_before_content);

    2)

    function add_before_content($content) {
    return ‘Default Message’.$content;
    }
    add_action(‘publish_post’,add_before_content);
    add_action(‘update_post’,add_before_content);
    add_filter(‘the_content’, add_before_content);

  2. Thanks for this, though is it possible to add line breaks in the content? I wanted to add a number of headings but they all appear as one long string rather than below each other.

    1. Sure just enter normal html tags and you’ll get line breaks, for example you can substitue the $content variable in my example above as follows: $content = “If you enjoyed this post, make sure to subscribe to my rss feed.
      This goes on the second line”;

      That will give you content over two lines.

Leave a Reply

Your email address will not be published.

From web hosting to WooCommerce plugins and backup services, we have put together a collection of exclusive coupons and deals just for you.
WP Mayor_Icon_white

Reader Survey

Supercharge your WooCommerce store!