Post Pic

How to: Automatically insert text in WordPress editor

Do you always insert the same text on all your posts, for exemple to tell people to subscribe to your rss feed? If yes, you should definitely set up WP to have it automatically inserted in the editor.

Really simple: Just open your functions.php file, and paste the following code:

<?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.";
	return $content;
}
?>

Save the file, and create a new post: The "If you enjoyed this post, make sure to subscribe to my rss feed." text is already in WordPress editor!

Credits goes to Justin Tadlock for this awesome recipe!

Related Posts

Related Posts

No related posts.

27 Responses

Apr 17 2009 13:52

Perfect for repetitive text.

Can we use HTML tags in pre-filled text?

Apr 17 2009 14:48

Thanks for the tips. I guess this is the way to go if I don’t always want to include some text in the end of the post. With this, the blogger has a choice to delete it or leave it as is.

Apr 17 2009 22:26

tnx for this tip! its very useful

Apr 18 2009 01:18

@CLAT Guru: Yes, you can preload any text into the text editor using this filter. Just make sure you’re escaping special characters properly (i.e. single or double quotes) so as to be proper PHP strings. I preload a whole bunch of stuff … IMG tags, DIV’s with special class names that I might want to include in each post, etc.

Apr 18 2009 21:13

I put together a plugin the other day to take advantage of this – it uses the wordpress visual editor for the default post content, so you can edit html, and insert images and other elements as you would normally in a post. It also handles default post meta.

Default Post Content Plugin

Apr 18 2009 21:22

Yeah i just used it. :) It’s very useful , thank you .

Apr 18 2009 22:18

this post very good…for my forum
This is a perfect
thanks

Apr 21 2009 04:59

Wow, this is even better than your last tip about WP Shortcodes. I was using a shortcode to insert the “Get Adobe Acrobat Reader” info, and went one better by editing the quicktags.js file to automatically insert [get] there. This is much better and cleaner. :)

Apr 24 2009 10:56

Great and simple Trick!

Thanks.

Apr 30 2009 12:20

Thank you Justin,
Thank you Peter (for Default Post Content Plugin!).

Apr 30 2009 13:42

I am using it now, thanks for sahring

May 01 2009 16:03

great concept. i like the plug-in approach even better because it becomes easier to maintain/change.

May 21 2009 13:12

// The filter function
function my_the_content($content){
global $post, $wpdb;
return $content.’Subscribe to my RSS … bla … bla … bla’;
}
// Low priority to append last
add_filter(‘the_content’, ‘my_the_content’, 9999);
// So much easier …

May 29 2009 21:23

Wowwwwwwwwwwwwwwwww, so amazing tip.

Jun 18 2009 05:14

Hi! Thanks for the tip! Say if you need to add more text, say, maybe another paragraph of something, how do u go about doing it? Do you just continue from there or I have to add another function?

Thanks!

Sep 18 2009 17:46

Anyone know how to do this for a page template? As in I want to create a page template, that when selected, automatically inserts content into the editor — but only for this page template and not all posts/pages…

Dec 14 2009 21:10

What is the syntax used to create a link in the php code? I want to turn the RSS in the string into a clickable link but can’t figure out the proper way to do it.
Thanks

Jan 20 2010 13:25

Would it be possible to display content only on certain page-templates?
How would the code look like?

Jul 22 2010 20:22

Wow this is perfect for a shortcode I was using in all my posts thank you!!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required