I need to adjust how the featured image is displayed in their blog module.

I need to change the display of the Featured Image from an IMG tag to a Background Image. So I can modify the frame (DIV) of the image without distorting the image itself.

I was able to do this for the default blog page (index.php) of my child theme. See any category page on my site.

I need to do the same to the Elegant Themes Blog Module.

I narrowed down to the function where this edit needs to go. But I'm unsure how to add it into my child theme's functions.php file.

This is basically the code (cut out the unnecessary parts):

add_shortcode( 'et_pb_blog', 'et_pb_blog' );
function et_pb_blog( $atts ) {


    query_posts( $args );

    if ( have_posts() ) {
        while ( have_posts() ) {

            $post_format = get_post_format();

            $thumb = '';

            $width = 'on' === $fullwidth ? 1080 : 400;
            $width = (int) apply_filters( 'et_pb_blog_image_width', $width );

            $height = 'on' === $fullwidth ? 675 : 250;
            $height = (int) apply_filters( 'et_pb_blog_image_height', $height );
            $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
            $thumb = $thumbnail["thumb"]; 

            $no_thumb_class = '' === $thumb || 'off' === $show_thumbnail ? ' et_pb_no_thumb' : '';

            if ( in_array( $post_format, array( 'video', 'gallery' ) ) ) {
                $no_thumb_class = '';
            } ?>

        <article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' . $no_thumb_class ); ?>>

        <?php if ( 'off' === $fullwidth || ! in_array( $post_format, array( 'link', 'audio', 'quote', 'gallery' ) ) ) { ?>
            <?php if ( ! in_array( $post_format, array( 'link', 'audio' ) ) ) { ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php } ?>


                if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) {
                    if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) :
                            '<div class="et_main_video_container">
                    elseif ( 'gallery' === $post_format ) :
                    elseif ( '' !== $thumb && 'on' === $show_thumbnail ) :
                        if ( 'on' !== $fullwidth ) echo '<div class="et_pb_image_container">'; ?>
                            <a href="<?php the_permalink(); ?>">
                                <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
                        if ( 'on' !== $fullwidth ) echo '</div> <!-- .et_pb_image_container -->';


Just beneath the line that contains $thumb = $thumbnail["thumb"]; I want to add this line of code:

$feat_image = wp_get_attachment_url( get_post_thumbnail_id(/* $post->ID */) );

Next I need to change

<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?> to

<div class="post-top-feat_img" title="blog-post-image" style="background: url(<?php echo $feat_image; ?>) no-repeat; background-size: cover;"></div>

Again I'm not sure how to appropriately add this to my child theme's functions file. When I follow what Elegant Themes' support staff says, I get this error.

Fatal error: Cannot redeclare et_pb_blog() (previously declared in /childTheme/functions.php:310) in /parentTheme/functions.php on line 4026

I've tried removing the shortcode a few different ways and re-adding it again with the new code in my child theme, but that either spits out the same error or just ignores it. Not sure where to go from here. I can make this work in the parent theme, but I'd rather not do that.

Any help is appreciated.


Child theme are loaded first than parent theme. And unlike other template files functions.php of child theme get merged with parent theme's functions.php instead of being overwritten.

So a function i.e. et_pb_blog() declared in parent theme can not be re-declared in child theme.


  1. Remove the shortcode in child theme
  2. Add it again with child theme but with different callback function name.
  3. You are buffering content but not returning what is in buffer. So complete the code with returning buffered content.


/* Remove shortcode that was added in parent them */

add_shortcode('et_pb_blog', 'et_pb_blog_custom');
 * Add the shortcode again with diffrent function name
 * @return string $shortcode_content
function et_pb_blog_custom($atts) {

    //Do watever you want

    $content = ob_get_contents(); //Get the buffer contnet
    ob_end_clean(); // turn off buffering
    return $content; // Return the content

Suggestion: Never use query_posts() instead try to use get_posts() or mostly preferred WP_Query(). Continue reading here

  • It's a good idea to not waste time answering off-topic questions, as they will get closed and/or deleted, and such answers encourage other off-topic questions. – markratledge Mar 17 '16 at 18:25
  • Yes I agree and never do this. But if you look at the question OP just mentioned theme name and in question and answer there is nothing related to theme! Please let me know if you still feel it off topic I won't mind to delete my answer @markratledge ;) – Sumit Mar 17 '16 at 18:28
  • I didn't ask you to delete your answer; I said the question will get closed or deleted by the moderators. – markratledge Mar 18 '16 at 0:28
  • Ok, thanks for the answer Sumit, I'll give that a shot. But what is wrong with my question in the first place? This is a WordPress forum isn't it? And why was the mention of the DIVI theme removed? This issue is with that theme. – Jeff Sydor Mar 22 '16 at 14:39
  • Also, the use of query_posts() is from the original parent. If I use either of the other 2, will it still work? – Jeff Sydor Mar 22 '16 at 14:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.