2

I was wondering, is it possible to set default text to appear inside "text" part of the wysiwyg located on Create post page? So every time you click add new post that text would be there waiting for you?

5

There is a filter named default_content. It does exactly what the name says. :)

Example:

add_filter( 'default_content', 't5_preset_editor_content', 10, 2 );

/**
 * Fills the default content for post type 'post' if it is not empty.
 *
 * @param string $content
 * @param object $post
 * @return string
 */
function t5_preset_editor_content( $content, $post )
{
    if ( '' !== $content or 'post' !== $post->post_type )
    {
        return $content;
    }

    return 'This is the <em>default</em> content. You may customize it.';
}

As you can see, the post type is already available, so you could set different defaults for different post types.

Related filters are default_title and default_excerpt. They work the same way.

You can also send someone a link with parameters for content, post_title and excerpt:

http://example.com/wp-admin/post-new.php?content=hello+world%21&post_title=Sample+Title&excerpt=custom+excerpt

Output:

enter image description here

  • I type too slowly, apparently. Exactly the answer I was going to give. – Pat J Apr 29 '13 at 20:40
  • @PatJ I didn’t type that much. – fuxia Apr 29 '13 at 20:41
  • toscho has beaten me before too @PatJ :) – Andrew Bartel Apr 29 '13 at 21:43
  • @toscho goes into functions.php correct? – Ilya Knaup Apr 29 '13 at 23:47
  • @IlyaKnaup Please, no. :) Make a plugin for that, something like this one. – fuxia Apr 30 '13 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.