WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding a "template html" to default Post (14 posts)

  1. joshdw
    Member
    Posted 4 years ago #

    Hey all,
    I need help making a default post template,

    Normally you get on the Add New Post a blank textbox and there you enter your posts body.
    I would like to have a html code already entered in that textbox and html view is automaticly selected every time I visit the Add New Post page.
    Please help me.

    Heres a pic i made to explain:
    This is default:

    http://i41.tinypic.com/5min8p.png

    This is what I want it to be as default:
    http://i43.tinypic.com/2cwt0eb.png

  2. joshdw
    Member
    Posted 4 years ago #

    Bump, my posts seem to be disappeering

  3. joshdw
    Member
    Posted 4 years ago #

    I searched for over 20 hours now and i cant find a thing!

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    There's a filter available just for this kind of thing, it will work regardless of whether the editor is set to HTML or Visual mode.

    add_filter( 'default_content' , 'my_default_content' );
    function my_default_content( $post_content ) {
    
    	$post_content = '<div class="test-default-content">Hello World!</div>';
    
    	return $post_content;
    }

    There's also a further two filters available for the default title and excerpt..

    default_title
    default_excerpt

    .. both would work in the same manner as the filter above.

  5. joshdw
    Member
    Posted 4 years ago #

    Where do i add these , and thanks for your response!

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    Easiest place, functions.php of your theme, else just create a file with a plugin name and install it as a plugin, whichever you prefer.

    Example as a plugin..

    <?php
    /*
    Plugin Name: Set Default Post
    */
    add_filter( 'default_content' , 'my_default_content' );
    function my_default_content( $post_content ) {
    
    	$post_content = '<div class="test-default-content">Hello World!</div>';
    
    	return $post_content;
    }

    Create a file, give it a php extension (can be called anything you like), and plonk the above into the file. Upload the file to the plugins folder, then activate it via the plugins page as you would any other plugin.

  7. joshdw
    Member
    Posted 4 years ago #

    Yeah i didnt know how to do this :) Life saver, just added at the end of my functions file and it works perfect!

    TYSM

  8. joshdw
    Member
    Posted 4 years ago #

    1 Last question, is it possible to add a text, normal text underneither or above the content box?

    Add new post
    Textbox to enter details here
    underneith that textbox: "<p><Dont forget to add picture</p>"

  9. Mark / t31os
    Moderator
    Posted 4 years ago #

    Well there's no appropriate hooks, but we could use some jQuery to do it..

    You can add this additional code to the above.

    add_action( 'admin_head-post-new.php' , 'reminder_message' );
    function reminder_message( ) {
    	?>
    	<script type="text/javascript">
    	/* <![CDATA[ */
    		jQuery(document).ready( function($) {
    			$('#postdivrich').prepend("Don't forget to add a picture.");
    		} );
    	/* ]]> */
    	</script>
    	<?php
    }

    :)

  10. joshdw
    Member
    Posted 4 years ago #

    If i could i would rep + you now!

    And i came across 1 last question,

    On Dashboard, the text:

    Theme News Top with 0 Widgets
    You are using WordPress 2.9.2.

    Anyway to edit or maybe add a line of text to that?
    Thanks SO much!

  11. Mark / t31os
    Moderator
    Posted 4 years ago #

    Add an action to rightnow_end and you can add content after the existing content in the right now widget.

    Unfortunately there are not any other hooks available (well there's one more, but it's right after to the suggested one, so it'll do exactly the same).

    Example usage:

    add_action( 'rightnow_end' , 'my_custom_rightnow' );
    function my_custom_rightnow() {
    	echo 'Hello World!';
    }

    Hope that helps... :)

  12. joshdw
    Member
    Posted 4 years ago #

    Worked for adding text :D Thanks thats all my problems solved!

    Love you, no homo but really do!
    Thanks a lot for helping a newbie to WP as me :P
    Josh

  13. Mark / t31os
    Moderator
    Posted 4 years ago #

    You're welcome.. :)

  14. tmelbs
    Member
    Posted 3 years ago #

    @Mark / t31os - is there any way to define the reminder message for a specific custom post type only?

    Thanks

    T

Topic Closed

This topic has been closed to new replies.

About this Topic