1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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
    SEMrush
    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
    SEMrush