Skip to content

Instantly share code, notes, and snippets.

@selul
Last active August 31, 2022 16:33
Show Gist options
  • Save selul/8279bfcfe611b68515eaab4d8a16efbf to your computer and use it in GitHub Desktop.
Save selul/8279bfcfe611b68515eaab4d8a16efbf to your computer and use it in GitHub Desktop.
Redirect Yoast attachments redirects to Optimole urls.
<?php
/*
* Plugin Name: Optimole Tweak - Redirect Yoast attachments to Optimole urls.
* Version: 0.0.1
*/
add_filter( 'wpseo_attachment_redirect_url', function ( $url ) {
return apply_filters( 'optml_content_url', $url );
}, 999 );
add_filter( 'attachment_link', function ( $url, $id ) {
if ( is_admin() ) {
return $url;
}
return wp_get_attachment_image_url( $id, 'full' );
}, 999, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment