• Hi,

    I’m trying to set up wordpress for when you create a post (post-new.php), it loads a default template in the editor with a specific format.

    The way I’m trying to do is putting a filter in the file functions.php in my theme (graphene) as follows:

    ————————————————————-
    add_filter (‘the_editor_content’,’plantilla_entradas’);

    function plantilla_entradas ($the_content) {
    $the_content = “”;
    $the_content = $the_content . “<table width=\”100%\”>”;
    .
    .
    .
    $the_content = $the_content . “</table>”;

    return $the_content;
    }
    ————————————————————-

    The fact is that when I go to add a new entry, is perfect, the template comes in the editor without any problem but when I go to edit a post that is already created, it overwrites the contents (it doesn’t delete them from the DB) and consequently I can not edit the post.

    From what I’ve seen about the hook I’m using “the_editor_content”, that is what it makes.

    My question is… is there any other hook to affect only the part of creation and not the edit one? or do you know any other way to put templates in the posts creation phase?.

    Thank you very much.
    Bye.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I use the plugin Article Templates to achieve this. It lets you build multiple templates then when you make a new post you have a drop down menu. When you select the template you want it populates the new post.

    Hope this helps,
    Rab

    It’s doing exactly what you’re telling it to do – and you’re telling it to blank-out the existing content:

    function plantilla_entradas ($the_content) {
         $the_content = "";
         $the_content = $the_content . "<table width=\"100%\">";
         ...
         $the_content = $the_content . "</table>";
    
         return $the_content;
    }

    I would change that to a conditional that checks to determine if any content exists, and if so, to return it rather than replacing it:

    function plantilla_entradas ( $the_content ) {
    
         if ( ! empty( $the_content ) {
              return $the_content;
         } else {
              $the_content .= "<table width=\"100%\">";
              $the_content .= ...;
              $the_content .= "</table>";
         }
         return $the_content;
    }

    P.S. use $the_content .= instead of $the_content = $the_content .

    Thread Starter jamapla

    (@jamapla)

    Hi again,

    the two solutions works great for me!!!

    thank you guys!!
    Bye.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post creation template’ is closed to new replies.