• Resolved Jaya

    (@moyajaya)


    I was looking for ways to preset html content to the editor upon the creation of new posts. I’ve found many examples to how to do that for text but i wasn’t able to figure out how to do the same thing with html content. (ex: text + images). Here is the example I’ve found:

    add_filter( 'default_content', 'my_editor_content' );
    
    function my_editor_content( $content ) {
    
        $content = "my-preset-content-here";
    
        return $content;
    }

    Any help in the matter would be appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • $content = '<img src="some/path/to/some/image/example.jpg" /><p>Hello World!</p>';

    Simply ensure that if the string contains any single quotes that you escape them, like so..

    $content = '<img src="some/path/to/some/image/example.jpg" /><p>It\'s christmas</p>';

    Of course, you don’t need to do that for the single quotes that start and end the string, only those that occur inside the string..

    I think it’s appropriate to use entities instead. Even though it get converted when saved.

    ... <p>It’s christmas</p> ...

    Technically, what you have there is a closing single quote, but if you want to use that, then sure, but use the HTML entity..

    <p>It&#146 ;s christmas</p>

    Without the space before the semi-colon(forum converts the entity – see below)..

    <p>It’s christmas</p>

    Thread Starter Jaya

    (@moyajaya)

    Thank you very much!! That worked 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help on presetting HTML content in the editor with function filter’ is closed to new replies.