【发布时间】:2017-07-09 00:15:25
【问题描述】:
出于某些原因,在更新了几项内容后,在我们的 wordpress 网站上的自定义字段中会自动在每个撇号前添加 3 个反斜杠。
示例:src="abc" 将导致 src=\\\"abc\\\"
我在functions.php 中有一个函数,用于连接网站。现在我需要删除那些反斜杠。这是原始函数:
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();
}
这是我尝试删除反斜杠的方法,但它只删除了 2 个反斜杠,而不是全部 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();
}
错在哪里?
【问题讨论】:
标签: php wordpress stripslashes