• Hi all

    how can I add default text to a new article..

    i tried this

    add_filter( 'default_content', 'my_editor_content' );
    
    function my_editor_content( $content ) {
    
    	$content = "This is some custom content I'm adding to the post editor because I hate re-typing it.";
    
    	return $content;

    and this

    function preset_content() {
    global $post;
    
    if ( $post->post_content == '' and $post->post_type == 'post' ) {
    $default_content = 'my preset content text';
    add_post_meta($post->ID, 'my custom field', 'my value', true);
    } else
    {$default_content = $post->post_content;} 
    
    return $default_content;
    }
    
    add_filter('the_editor_content', 'preset_content');

    in wp-includes/function.php

    but i only get errors..

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter gms0012

    (@gms0012)

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED

    tmelbs

    (@tmelbs)

    Hello,

    I used this code and made a plugin specifying a specific post type and it worked perfect. So then I created another plugin and used the same code but designated a different post type and for some reason only one plugin will work at a time… each plugin works independently of the other one but I cannot activate both at the same time or only one of them will work…

    Here is the general code for each…

    Post Type A

    function preset_content_post_type_a() {
    global $post;
    
    if ( $post->post_content == '' and $post->post_type == 'post-type-a' ) {
    $default_content_post_type_a = 'my preset content text for post type a';
    add_post_meta($post->ID, 'my custom field', 'my value', true);
    } else
    {$default_content_a = $post->post_content;} 
    
    return $default_content_a;
    }
    
    add_filter('the_editor_content', 'preset_content_post_type_a');

    And now Post Type B

    function preset_content_post_type_b() {
    global $post;
    
    if ( $post->post_content == '' and $post->post_type == 'post-type-b' ) {
    $default_content_post_type_b = 'my preset content text for post type b';
    add_post_meta($post->ID, 'my custom field', 'my value', true);
    } else
    {$default_content_b = $post->post_content;} 
    
    return $default_content_b;
    }
    
    add_filter('the_editor_content', 'preset_content_post_type_b');

    Can anyone help me understand how to get both working at the same time so that when I create a new post with the custom post type these templates will work?

    I am running 3.1.1

    Thank you very much,
    Tmelbs

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add default text to new article’ is closed to new replies.