Add default content for a new post in WordPress


o what if we can automate that type of text such that it shows up automatically whenever you start writing a new post ? Yes, that will be something awesome, hence in this blog post I am going to show you how you can do that in your blog. I am sure there must be some plugins out already for this trick, but my aim here is to make you understand how simple it is to do your own thing icon smile Add default content for a new post in WordPress

Since you know WordPress comes with lot of hooks and filters to make the development process easier. Hence we are going to use a filter which will allow us to populate some pre-defined text while creating a new post. Now let us see how to go about it.

Open functions.php which is present in the themes folder of your blog and copy the following code at the end of the file.

 
/**
 * Add a filter called default_content
 */
add_filter('default_content', 'add_pre_populated_content');

/**
 * function will get called by the filter defined above
 */
function add_pre_populated_content( $content ) {
        // you can change the content as per your requirement
	$content = "<p>Stay Digified!!<br/>Sachin Khosla</p>";
	return $content;
}

As you can see the we have added a filter called “default_content” in WordPress which is used when you hit “Add New Post” in your WordPress Admin dashboard. You can put as much content as you want to add as per your requirement. I told you already that it’s simple, right ? So go ahead and add this code snippet in your blog and enjoy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s