WordPress.org

Ready to get started?Download WordPress

Forums

Modify php the_content (13 posts)

  1. cavamondo
    Member
    Posted 3 years ago #

    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>

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. cavamondo
    Member
    Posted 3 years ago #

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

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

    in the:
    plugin_function_name

  4. esmi
    Forum Moderator
    Posted 3 years ago #

  5. cavamondo
    Member
    Posted 3 years ago #

    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?

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  7. cavamondo
    Member
    Posted 3 years ago #

    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>

  8. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  9. cavamondo
    Member
    Posted 3 years ago #

    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?

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  11. cavamondo
    Member
    Posted 3 years ago #

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

  12. cavamondo
    Member
    Posted 3 years ago #

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

  13. esmi
    Forum Moderator
    Posted 3 years ago #

    Am i on the right path?

    Yes

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

    Correct.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.