2016-07-14 12 views
-1

私は現在、 "section_content"という値を持つAFCを通じて投稿に複数のコンテンツを取り込んでいます。さらに、以下のコードを使用して私のWP投稿を整理しています。 ACFも含めてこのフィルタを変更するにはどうすればよいですか?functions.phpを使ってWordpressでACFをフィルタリングする最も良い方法

<?php 
/** 
* Clean posts from inline styling and unnecessary tags 
*/ 

add_filter('the_content', 'clean_post_content'); 
function clean_post_content($content) { 
    if (is_single()) { 
     $patterns = array(
     '/(<[^>]+) style=".*?"/i',      // Remove inline styling 
     '/<\/?font[^>]*>/',        // Remove font tag 
     '/<(p|span)>(?>\s+|&nbsp;|(?R))*<\/\1>/',  // Empty p, span (font tags already removed) 
     '/(<h[1-6]>[^<]*)<\/?strong>(.*?<\/h[1-6]>)/', // h1-6 
     ); 

     $replacements = array(
     '$1', 
     '', 
     '', 
     '$1$2' 
     ); 

     $old_content = ''; 
     while ($old_content != $content) { 
      $old_content = $content; 
      $content = preg_replace($patterns, $replacements, $content); 
     } 
    } 
    return $content; 
} 

?> 

答えて

0

ACF Filtersを使用できますか?私は通常、フックを印刷する前に自分のカスタムフィールドの値を修正または変更するためにacf/format_valueにフックします。

あなたも同じように、唯一の特定のフィールドタイプにフックすることができます。

function acf_brand_trademark($value, $post_id, $field) { 
    $value = preg_replace('/Brand /', 'Brand<sup>™</sup> ', $value); 
    return $value; 
} 

add_filter('acf/format_value/type=textarea', 'acf_brand_trademark', 10, 3); 
add_filter('acf/format_value/type=text', 'acf_brand_trademark', 10, 3); 

は、この情報がお役に立てば幸い!

関連する問題