php - Insert featured image into post content -
i using wordpress theme website , i'm trying alter php featured image displayed within post content instead of before or after (the top of post or bottom)
here's original code:
<?php if ( ( has_post_thumbnail( $post_id ) || '' != get_post_meta( $post_id, 'thumbnail', true ) ) && 'on' == et_get_option( 'origin_thumbnails' ) ) { ?> <div class="post-thumbnail"> <?php if ( has_post_thumbnail( $post_id ) ) the_post_thumbnail( 'full' ); else printf( '<img src="%1$s" alt="%2$s" />', esc_attr( get_post_meta( $post_id, 'thumbnail', true ) ), the_title_attribute( array( 'echo' => 0 ) ) ); ?> </div> <!-- end .post-thumbnail --> <?php } ?> <?php the_content(); ?>
here's how tweaked in child theme:
<?php the_content(); ?> <?php if ( ( has_post_thumbnail( $post_id ) || '' != get_post_meta( $post_id, 'thumbnail', true ) ) && 'on' == et_get_option( 'origin_thumbnails' ) ) { ?> <div class="post-thumbnail"> <?php if ( has_post_thumbnail( $post_id ) ) the_post_thumbnail( 'full' ); else printf( '<img src="%1$s" alt="%2$s" />', esc_attr( get_post_meta( $post_id, 'thumbnail', true ) ), the_title_attribute( array( 'echo' => 0 ) ) ); ?> </div>
i'm not fluent in php , accomplished moving featured image bottom of post :-/. posted theme's forum , given following code didn't seem anything.
add_filter( 'the_content', insert_featured_image, 20 ); function insert_featured_image( $content ) { $content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->id, 'post-single'), $content, 1 ); return $content; }
can point me in right direction?
tia!
what reasoning behind attempting move featured image content? wordpress codex gives following example:
// check if post has post thumbnail assigned it. if ( has_post_thumbnail() ) { the_post_thumbnail(); } the_content();
basically, the_post_thumbnail(); display image selected featured image while the_content(); displaying inputted wysiwyg post or page.
if you're attempting matches design or layout, might want @ applying addition markup , styles area. if require text before , after featured image should custom fields.
Comments
Post a Comment