• 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)
  • Thread Starter 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

    Thread Starter 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?

    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.

    Thread Starter 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>

    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.

    Thread Starter 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?

    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.

    Thread Starter 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 (); ?>

    Thread Starter cavamondo

    (@cavamondo)

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

    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.