WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Default post layout (6 posts)

  1. Zandmachine
    Member
    Posted 4 years ago #

    I was wondering if it possible to define a default layout of a post. Because I always blog with a certain post-layout, I would like to save me some time by typing everything again... so it would be very interesting if in the wp-admin panel, the layout is allready "pasted" in my new post text field.

    Is this possible? And if so, how? Which .php file do I have to edit and in what section exactly?

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    Yes you can define default content.

    <?php
    function my_default_content($content) {
    	$content = 'Your default content';
    	// $content = '<p class="example">Hello world!</p>';
    	return $content;
    }
    add_filter( 'default_content', 'my_default_content' );
    ?>

    You can do the same for the title and the excerpt to, same as above just replacing default_content for default_title or default_excerpt.

  3. Zandmachine
    Member
    Posted 4 years ago #

    and where do I have to edit this?

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    functions usually reside in functions.php in your theme

  5. Mark / t31os
    Moderator
    Posted 4 years ago #

    In plugin form..

    1. Create a new file, call it anything you like, but give the file a .php extension (aka a php file).
    2. Copy the code below into that file.

    <?php
    /*
    Plugin Name: My Default Content
    */
    function my_default_content($content) {
    	$content = 'Your default content'
    	// $content = '<p class="example">Hello world!</p>'
    	return $content;
    }
    add_filter( 'default_content', 'my_default_content' );

    3. Save the file.
    4. Upload to the plugins folder.
    5. Activate the plugin like you would any other.

    If you want to make any changes, just edit the file you've placed on the server (or use the builtin plugin editor if you prefer). I've obviously provided example HTML above, but if you need some help putting something specific into the code feel free to ask.

  6. Zandmachine
    Member
    Posted 4 years ago #

    thank you so much! this really helped me out!

Topic Closed

This topic has been closed to new replies.

About this Topic