How to set default text for new wordpress posts
Wordpress backend, new page

Sometimes you are using the same template for each post. If you are using wordpress you can just put it as default text for new posts instead of copying it from other posts.

Just put this code in the functions.php file of your active wordpress theme to add a default text for new pages:

add_filter( 'default_content', 'nddt_default_editor_content' );

function nddt_default_editor_content($content) {
    global $post_type;    
    if ($post_type = "page"){
        $content = "Put this in the textfield of a new page";
    }
    return $content;
}

The global variable $post_type contains the slug of the posttype. This way you can set a different default text for each type of content.

If you want to add a diffrent default text for posts you could extend the method this way:

function nddt_default_editor_content($content) {
    global $post_type;    
    if ($post_type = "page"){
        $content = "Put this in the textfield of a new page";
    }
    if ($post_type = "post"){
        $content = "Put this in the textfield of a new post";
    }
    return $content;
}

Any posttype you don’t mention here won’t have a default text.

This solution only works for wordpress. If you are intressted in similar solutions for another content management system (CMS) ask me about it in the comments.

LEAVE A REPLY

Please enter your comment!
Please enter your name here