いくつかの理由のうちいくつかの理由から、カスタムフィールドのワードプレスサイトでは、自動的にアポストロフィの前に3つのバックスラッシュが追加されます。 例:src="abc"
は私がウェブサイトにフックのfunctions.php内の関数を持っているsrc=\\\"abc\\\"
stripslashesで3つのバックスラッシュを削除する
になります。今私はそれらのバックスラッシュを削除する必要があります。
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();
}
ではないの除去:これはのorignal機能ですか?あなたはstr_replaceを使用することができます
あなたの考えに感謝します。私は以下のように変更しましたが、バックスラッシュを削除しません。なぜなのかご存知ですか? '関数は($ text){ を返しますstr_replace(" /// "、" "、$ text); } add_action( 'woocommerce_before_single_product'、 'headline_placeholder'); function headline_placeholder(){ グローバル$ wp_query; $ postid = $ wp_query-> post-> ID; $ meta = get_post_meta($ postid、 'productheadline'、true); echo removlashes($ meta); wp_reset_query(); } ' –