Changing how Wordpress theme outputs post images

Discussion in 'PHP' started by phantom, May 11, 2017.

  1. #1
    I have a Wordpress theme and I am trying to change how it outputs the post images.

    I am here is my code I am trying in functions.php

    add_filter( 'post_thumbnail_html', 'my_image_func', 10, 7);
    function my_image_func($html, $post_id ) {
      $url = wp_get_attachment_url($post_id); // Grab the current image URL
        $html = "<div style='background: url(\"$url\"); ></div>";
        return $html;
      }
    PHP:

    But for some reason $url turns up empty

    Can anyone point me in the right direction on how to fix this?
     
    phantom, May 11, 2017 IP