Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PunchRockgroin/083d2a9c76470a82470eddfb4fbeca56 to your computer and use it in GitHub Desktop.
Save PunchRockgroin/083d2a9c76470a82470eddfb4fbeca56 to your computer and use it in GitHub Desktop.
Replace Visual Composer / WPBakery Page Builder default image when no featured image present
function replace_vc_gitem_post_image_background($output){
// Get the URL to replace in string background-image: url('https://yoursite.com/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png') !important;
$url = get_site_url(null, '/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png');
// Full http(s) path to image
$new_url = 'full-uri-to-new-image.ext'; // 1024x1024 image
// String Replace
$new_output = str_replace($url, $new_url, $output);
// Return new string
return $new_output;
}
add_filter('vc_gitem_template_attribute_post_image_background_image_css_value', 'replace_vc_gitem_post_image_background', 10);
@ddebarros316
Copy link

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment