WordCast

Add Preset Text to WordPress Posts

You may often find yourself needing some sort of text or code in every post you make. Perhaps you want to remind your readers to subscribe to your feed at the bottom of your posts, or maybe you have a link to your Twitter at the top of each article you write. In this hack, I’ll show you how to add preset text to posts in WordPress.

Now, to make this happen, you’ll need to use WordPress.org, the self-hosted “flavor” of WordPress run on your own server with your own database that you pay for. If you use WordPress.com’s free hosting, you’ll have to find another way to do things. Some recommend saving a template post as a draft and then modifying it from there whenever you need it, or simply copying and pasting.

If you want to go the plugin route, there are many different WordPress plugins available for post “templates”. Try them out, read the reviews, and see what works for you. Here are some of the big ones:

If you’re more of an advanced user and would rather get really hackey and codey, you can edit your theme’s functions.php file to set a certain text to be in each post you publish.

WARNING! Modifying any PHP file like this can cause problems in your WordPress theme if something goes wrong, so be careful! Also, keep in mind that any changes you make will be gone when you switch your theme or re-upload it later.

Justin Tadlock offers this this solution: Open your theme’s functions.php file in your favorite text editor (Dave recommends Notepad Plus for Windows and TextWrangler for Mac) and add the following code:

<?php
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "Your custom text you always want in every post automatically. Put that here.";
return $content;
}
?>

Remember, this will only add text to your new posts, and will only fill in this text while you’re using this theme.

Hacks is a new feature on WordCast, your source for everything WordPress and blogging, delivered to your eyes and ears 24/7. We’d love to get your feedback! Comment on this post below, call our voicemail at 818-924-3388, email us at mail [at] wordcastpodcast [dot] com, or yell at us on Twitter- we’re @WordCast.

Leave a Reply