I want to remove the website url from all the_post_thumbnail()
so they become relative and remove/add attributes from the output.
So far I got the following code added to functions.php of the theme, xcept I am not sure how to modify the thumbnail $html
for the second part.
Help is appreciated
add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
function my_post_image_html( $html, $post_id, $post_image_id, $size ) {
// Create relative url using pars_url in php
$relURL = wp_get_attachment_url( $post_id ); // Get Post thumbnail Src instead of permalink
$relURL = parse_url( $relURL );
$relURL = $relURL['path'];
//Pass the relURL to post_thumbnail_html modify the src attribute
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . $imgsrc .$post_id . '</a>';
return $html;
}
This is a pretty wonky function but it does the job, it will turn your post thumbnail into a relative url. Not sure why you would do this, use at your own caution, probably want to add some error checking.