WordPress.org

Support

Support » Plugins and Hacks » Modify php the_content

Modify php the_content

  • cavamondo

    @cavamondo

    Im trying to include the <?php the_post_thumbnail(); ?> into the “php the_content”, so that it automaticly will display the post thumbnail in the content by default .. is this possible?

    Looking for a way to put this into the php_the_content:

    <div id=”thumbnail”>
    <?php the_post_thumbnail(); ?>
    </div>

Viewing 12 replies - 1 through 12 (of 12 total)
  • esmi

    @esmi

    Forum Moderator

    cavamondo

    @cavamondo

    Thx for helping out … so how do i put the code:

    <div id=”thumbnail”>
    <?php the_post_thumbnail(); ?>
    </div>

    in the:
    plugin_function_name

    esmi

    @esmi

    Forum Moderator

    cavamondo

    @cavamondo

    Im not a skilled programmor but ill give it a go.

    So i need to define the put_thumbnail_in_content function in functions.php and and then place it in this: <?php add_filter( “the_content”, “plugin_function_name” ) ?>

    Is this correct?

    esmi

    @esmi

    Forum Moderator

    So i need to define the put_thumbnail_in_content function in functions.php

    Yes. You then need to add add_filter( "the_content", "plugin_function_name" ); to the same file (most developers seem to add it just before or just after their add filter function).

    In essence, you’re asking WP, to run the normal content filters and then add your custom code to the post content before it’s displayed on the page.

    cavamondo

    @cavamondo

    Something like this?

    <?php
    add_filter( “the_content”, “thumbnail_in_content” );

    function thumbnail_in_content() {}

    ?>

    <body>
    <?php add_filter( “the_content”, “thumbnail_in_content” ) ?>
    </body>

    esmi

    @esmi

    Forum Moderator

    No. You don’t include any <body></body> tags. You’re only adding something to the post content – the bit that’s is generated by <?php the_content();?> in the theme template.

    Look at the example in the Create_a_Filter_Function link I gave above.

    cavamondo

    @cavamondo

    The body tags was only to illustrate that the last bit was to be put in the body part of the the template whre the content is to be displayed ^^

    So, so far its correct then?

    esmi

    @esmi

    Forum Moderator

    The body tags was only to illustrate that the last bit was to be put in the body part of the the template whre the content is to be displayed

    No. add_filter( "the_content", "thumbnail_in_content" ) has to be added to your function file.

    cavamondo

    @cavamondo

    Hehe thx for the patience, im sure i will get it eventually, just need to get my head around the basics.

    So this is what ive got so far, and just to be sure. Am i on the right path?

    <?php
    add_filter( “the_content”, “thumbnail_in_content” );

    function thumbnail_in_content() {}
    ?>

    And this goes into the template.
    <?php the_content (); ?>

    cavamondo

    @cavamondo

    So im guessing now i have to look at the function “thumbnail_in_content”.

    esmi

    @esmi

    Forum Moderator

    Am i on the right path?

    Yes

    So im guessing now i have to look at the function “thumbnail_in_content”.

    Correct.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Modify php the_content’ is closed to new replies.
Skip to toolbar