• Resolved ScientiaMobile

    (@scientiamobile)


    Hi.
    My question is how to get the “real” image src out of wp_get_attachment_image_srcwhen Jetpack’s Photon is enabled?

    The full story here is that I have a plugin that needs to alter the src of images. When Photon is enabled it takes total control and prepend the hostname to the CDN. I need the url without that prefix.

    I try to disable it for a specific image with add_filter( 'jetpack_photon_skip_image', '__return_true' );which works well for the src attribute in the image tag, but, for responsive images the srcset is still prefixed with the CDN hostname. So looks like the jetpack_photon_skip_image trick does not apply for references in srcset.

    My plugin adds a filter to wp_calculate_image_srcset which in turn try to get the real urls from wp_get_attachment_image_src(). Still prefixed with CDN hostname. So looks like jetpack_photon_skip_image does not apply there either.

    I’ve also tried this hack: https://ethitter.com/2013/07/disable-jetpacks-photon-module-in-specific-situations/ but still the srcset is prefixed.

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ScientiaMobile

    (@scientiamobile)

    Update:
    Now, it looks like my function works as expected by adding a new url to the $sources array
    $sources[$size]['url'] = $new_url;
    When I dump the array, it contains what I expect (more or less). But by magic, this is photonized at a later stage… No idea where/when…

    Thread Starter ScientiaMobile

    (@scientiamobile)

    Problem identified:
    https://github.com/Automattic/jetpack/blob/master/class.photon.php#L620
    is basically overwriting the URL already changed by my filter ??

    Thread Starter ScientiaMobile

    (@scientiamobile)

    There is something fishy here since src and srcset are handled differently by photon. I found a workaround that feels a bit hacky.

    First do this

    if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
    	add_filter( 'jetpack_photon_skip_for_url', '__return_true' );
    }

    Then, set the priority of the filter for the wp_calculate_image_srcset hook to 11 so that it will run after other JetPack filters I’ve found which has prio 10.

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