Skip to content

Instantly share code, notes, and snippets.

@wpweb101
Last active September 15, 2018 07:25
Show Gist options
  • Select an option

  • Save wpweb101/8afa9942f04bc713b0251332b0055e42 to your computer and use it in GitHub Desktop.

Select an option

Save wpweb101/8afa9942f04bc713b0251332b0055e42 to your computer and use it in GitHub Desktop.
Social Auto Poster - Filter code for allowed relative image url instead of full image url
<?php // Do not add this if it's already added on your file.
// Filter code for allowed relative image url instead of full image url
add_filter('wpw_auto_poster_social_media_posting_image', 'wpw_sap_custom_relative_image_src');
function wpw_sap_custom_relative_image_src( $img_src ) {
if( !empty( $img_src ) ){
if( is_array( $img_src ) ){
$temp_srcs = $img_src;
foreach ( $temp_srcs as $key => $src ) {
if( ( strpos( $src, 'http://') !== 0 ) && ( strpos( $src, 'https://') !== 0 ) ) {
$img_src[$key] = site_url( $src);
}
}
} else{
if( ( strpos( $img_src, 'http://') !== 0 ) && ( strpos( $img_src, 'https://') !== 0 ) ) {
$img_src = site_url( $img_src);
}
}
}
return $img_src;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment