Pre-set Initial, Default Text in the WordPress Editor

It was a long time before I found the page that told me how to do it. I searched many times, and eventually found a discussion that gave a link, which took me to a page that told me what I needed to do. That page called it “preset text”. I had been searching on “initial text in WordPress editor” and “default text in WordPress editor”. Hopefully, this post will help others who search on those terms.

The link I found went to this page: Preset Text in the Editor.

Process

Here is the process that resulted:

  1. Go to Appearance > Editor > Theme Functions (functions.php) 
  2. At the end of the page, add the function below.
  3. Fill in the desired initial content.

Function

The code was pretty simple. I made the following tweaks:

  • I modified it to allow multi-line content. 
  • I left out the <?php ... ?> directives that were included in the sample, as they were already in the functions.php file.
    (Adding them seemed to interfere with the editor. All I saw was a blank screen after closing it, so I put the new code at the end of the existing <?php-block, just before the closing ?>. After that, everything worked fine.

Here is the code I added:

add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
  $content = <<<EOD
Your Initial Content Here
EOD;
  return $content;
}

Content

My initial-content text makes sure that I don’t forget the summary, the <!–more–> tag, or the copyright. It looks like this:

<blockquote>summary
</blockquote>
<!--more-->
<p> </p>
<p class="copyr">--copyright notice--</p>

Following Up

Of course, the change will need to be redone whenever the theme is updated, but that doesn’t happen all that often. And when it does, the change will have no effect on how the site operates.

All that will happen is that the next you create a post after an update, you’ll see a blank editor window. So if you’ve saved a copy of the code you added (as I did, in my Snippets file) it’s a simple matter to put it back. 

Copyright © 2017, TreeLight PenWorks

Add your thoughts...

Categories