preset text in the WordPress post editor

May 16, 2009 · Print This Article

There are built-in action and filter hooks that allow us to change things. We’ll be showing you how to use a simple filter to preset text in the WordPress post or page editor. This technique will work with both the visual and HTML editor.

We shouldn’t edit core files. Then what should we edit? Only our theme’s functions.php file. or, we could go through the process of making a plugin, but this is pretty simple stuff.

Open your functions.php in your favorite text editor and input following PHP code:

<?php

add_filter( 'default_content', 'my_editor_content' );

function my_editor_content( $content ) {

$content = "This is some custom content we're adding to the post editor.";

return $content;
}

?>

It’s as simple as that. Just a few lines of code. You could even add in some XHTML if you want.

This will only add your text to new posts. It will not add it to posts that have already been written or saved. And, you can always delete it when writing the post if it’s not needed.


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.