WordPress.org

Ready to get started?Download WordPress

Forums

New Page not blank (19 posts)

  1. Marc73
    Member
    Posted 2 years ago #

    Hi. It does not sound professional to ask my user to copy and paste the html code of 2 tables into the html source of each new page.

    Is not there a more elegant way of doing that? Plugin ? Child Theme?

  2. Shaan
    Member
    Posted 2 years ago #

    Your question is kind of vague. Could you specify exactly what the issue is? Also, if possible, drop of a URL?

  3. Marc73
    Member
    Posted 2 years ago #

    I have a user who almost in every single new page wants to have the same two tables that he fills in with data about the article on that page.

    My easy way of doing this is to copy-paste the required html code to the html source of the new page box editor.

    But it does not sound professional to ask a user to copy-paste the html code of those two tables to every new page.

  4. Marc73
    Member
    Posted 2 years ago #

    still not clear ?

  5. Shaan
    Member
    Posted 2 years ago #

    Put the code below into your functions.php file to have default text appear when you make a new post/page.

    <?php
    
    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;
    }
    
    ?>

    Let me explain the code above. The part that says:

    $content = "This is some custom content I'm adding to the post editor because I hate re-typing it.";

    is where you need to put in your content. You can put in html. Just add it inside the quotes to have the tables appear in every post/page. If you put in HTML, you have to make sure that you put a backslash before all of the single quotes and/or apostrophes. For example:

    $content = "<p>It\'s great to work on WordPress!</p>";

    Note the backslash before the apostrophe in "It's".
    Here is a plugin that will set the default text for you:
    http://wordpress.org/extend/plugins/default-post-content/

    I hope this helps!

  6. Marc73
    Member
    Posted 2 years ago #

    thank you munny. I sincerely appreciate your help.
    The plug-in "Default Post Content" does not serve my goal as my user is using Pages not articles.

    but I will try functions.php

  7. Shaan
    Member
    Posted 2 years ago #

    Let me see what I can do...

  8. Marc73
    Member
    Posted 2 years ago #

    munny, thank you for your help

    At which position in functions.php should I insert this code ?

    <?php

    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;
    }

    ?>

  9. Shaan
    Member
    Posted 2 years ago #

    Here are two solutions for pages:
    1. When you create the page, paste the table in so that your user has the table there for him/her (if the user creates the pages, move to the next option).
    2. Copy the code from page.php into a text editor like Notebook or TextEdit (plaintext editor), edit this page.php in your choice of editor like so:
    Add these five lines to the top:

    <?php
    /*
    Template Name: <em>[your page name here]</em>
    */
    ?>

    Change [your page...] to a template name like "Table" (without the quotes)
    THEN:
    Change this:
    <?php get_template_part( 'content', 'page' ); ?>
    To this:

    <?php get_template_part( 'content', 'page' ); ?>
    <?php include(“default_page_values.html”); ?>

    Once you have done this, upload it to your FTP client under wp-content>themes>[your theme name]. Make another file that MUST be called default_page_values.html in your editor. Put your default HTML/text in it. Upload to the same location where you uploaded the template.
    Now, whenever you make a new page, just choose the template that has your pre chosen name to have the default text there.
    (Sorry for the wait)

  10. Shaan
    Member
    Posted 2 years ago #

    <?php
    
    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;
    }
    
    ?>

    Put this anywhere. It, however, may not work. Try out my other post. It might work. If my other post does not work out, you will have to give me some time to research and see if I can find you some answers. In the mean time, some WordPress geniuses might answer your question!

  11. Marc73
    Member
    Posted 2 years ago #

    thank you.

    I tried this method:

    <?php
    add_filter( 'default_content', 'my_editor_content' );
    function my_editor_content( $content )

    it did not work and when I try to create a new page, I get a totally blank page in my browser. (IE9 on Win7)

    I tried the other method:

    <?php get_template_part( 'content', 'page' ); ?>
    <?php include(“default_page_values.html”); ?>

    But that also did not give the expected outcome. (the editing box of a new page remained blank when the right template is chosen in the drop-down menu to the right)

  12. Shaan
    Member
    Posted 2 years ago #

    Disregard this.

  13. Shaan
    Member
    Posted 2 years ago #

    Here is the real deal. This will work. I am sure.

    function dmg_default_text_in_editor( $content, $post ) {
      if ( 'page' == $post->post_type ) $content .= 'Default page content.';
      return $content;
    }
    
    add_filter( 'default_content', 'dmg_default_text_in_editor', 10, 2 );

    Replace 'Default page content' with your own content.
    ------
    Here is another code if you want to do this for both posts and pages:

    function dmg_default_text_in_editor( $content, $post ) {
      if ( 'page' == $post->post_type ) $content .= 'Default page content.';
      if ( 'post' == $post->post_type ) $content .= 'Default post content.';
      return $content;
    }
    
    add_filter( 'default_content', 'dmg_default_text_in_editor', 10, 2 );

    Replace the 'Default...' with your own content. Sorry about the other posts. Sometimes things just do not work... Anyway, hopefully this will be successful.

  14. Marc73
    Member
    Posted 2 years ago #

    thank you.
    I'd highly appreciate it if you kindly give me clear instructions such as: go to file.php, edit abc, replace with xyz.

    I am not sure what to do with the code you posted.

  15. Shaan
    Member
    Posted 2 years ago #

    Sorry about that! Just put it in your functions.php

  16. Marc73
    Member
    Posted 2 years ago #

    Thank you a MILLION!
    That worked.

    But how can I protect my changes against future theme updates?

  17. Shaan
    Member
    Posted 2 years ago #

    This will not protect it, in a way. Since your client/user probable has access to this theme editor, you do not want him/her to get rid of the code by mistake. Just put this line right above the changes in function.php:
    // Default text message here
    Edit the text with your own message telling the User not to edit the code below. You see this in a lot of themes. For example:
    // DO NOT EDIT THE FOLLOWING CODE.
    This will not affect any part of your site but is just a message in your theme editor telling your user not to edit the code.
    In your case, the following is what your code should look like (your own default text should be added):

    // DO NOT EDIT THE FOLLOWING CODE.
    function dmg_default_text_in_editor( $content, $post ) {
      if ( 'page' == $post->post_type ) $content .= 'Default page content.';
      return $content;
    }
    
    add_filter( 'default_content', 'dmg_default_text_in_editor', 10, 2 );

    Hope this helps!

  18. Marc73
    Member
    Posted 2 years ago #

    OK thank you very much munny. I appreciate your help.

  19. Shaan
    Member
    Posted 2 years ago #

    No problem!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags