Out of some reasons after updating several things, on our wordpress site in the custom fields are automatically addes 3 backslashes before every apostrophe.
Example: src="abc" will result in src=\\\"abc\\\"
I've got a function in functions.php where I hook into the website. Now I need to remove those backslashes. This is the orignal function:
add_action('woocommerce_before_single_product', 'headline_placeholder');
function headline_placeholder () {
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'productheadline', true);
wp_reset_query();
}
This is what I tried to remove the backslashes, but its only removing 2 backslashes, not all 3.
function removeslashes($string)
{
$string=implode("",explode("\\",$string));
return stripslashes(trim($string));
}
add_action('woocommerce_before_single_product', 'headline_placeholder');
function headline_placeholder () {
global $wp_query;
$postid = $wp_query->post->ID;
$meta = get_post_meta($postid, 'productheadline', true);
echo removeslashes($meta);
wp_reset_query();
}
Where is the mistake?
Maybe you can use str_replace, something like this:
Hope it helps!