• Resolved colabsadmin

    (@colabsadmin)


    Can someone provide a working example of the new filtering capabilities that’s been added to the wp_get_attachment_image_src function in 4.3? I’m trying to change the image source.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    add_filter( 'wp_get_attachment_image_src', 'ca_change_src', 10, 4 );
    function ca_change_src( $image, $attachment_id, $size, $icon ) {
       return array('https://www.google.com/images/nav_logo100633543.png', 167, 410, false );
    }

    It’s no different than any other filter, return whatever you wish the function to return. In this case it should be an array of image info. This frivolous example replaces all images with one of Google’s icon sprites. You’d likely want to add some logic to manipulate the $image string in some manner, and under certain conditions only.

    Thread Starter colabsadmin

    (@colabsadmin)

    I was soooo close. Thank you ??

    Moderator bcworkz

    (@bcworkz)

    Hehe, I know what you did because I made the same mistake ??
    You’re welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Filtering wp_get_attachment_image_src’ is closed to new replies.