Payament
Free Photos
WordPress Themes

How to pre-populate WordPress editor with default content

<?php add_filter( 'default_content', 'pu_default_editor_content' ); function pu_default_editor_content( $content ) { global $post_type; switch( $post_type ) { case 'post': $content = 'Default content for blog posts.'; break; case 'page': $content = 'Default content for pages.'; break; case 'portfolio': $content = 'Default content for your portfolio pages.'; break; case 'products': $content = 'Default content for blog posts.'; break; } return $content; }
If you’re often writing the same kind of post (articles, lists, code snippets, etc) you may find very useful to pre-populate the WordPress editor with some custom content. Here’s a super easy code snippet to do it.

This code has to be pasted into your theme’s functions.php file. It can be customized to deal with custom post types, as shown on line 16 and after.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.