Default Content

How to Add Default Content

Default Content

Advertisements

Have you ever noticed that the same wording appears in all of your posts? People frequently accomplish this by encouraging others to subscribe to their feeds, retweet the message, share it on Facebook, and so on. You may always add it right after the content with a simple tag, or you can make that text the default content in your WordPress post editor.

 

Simply open the functions.php file in your WordPress theme and insert the following code within the PHP tags.

1
2
3
4
5
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
    $content = "If you like this post, then please consider retweeting it or sharing it on Facebook.";
    return $content;
}
Advertisements

Then you’re done. Create a new post, and the new content should appear there.

 

(24th of January, 2013) – In the comments, one of our users inquired about how to add different content for different post types. The code below will teach you how to set distinct default content for each custom post type in your WordPress post editor:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
add_filter( 'default_content', 'my_editor_content', 10, 2 );
function my_editor_content( $content, $post ) {
    switch( $post->post_type ) {
        case 'sources':
            $content = 'your content';
        break;
        case 'stories':
            $content = 'your content';
        break;
        case 'pictures':
            $content = 'your content';
        break;
        default:
            $content = 'your default content';
        break;
    }
    return $content;
}
Advertisements

Leave a Reply