2016-12-15 7 views
1

私は例えば、私はスパンのスタイルを設定できるように、自動的に私の見出しの周りにスパンを追加する機能を持っている:Wordpressの高度なカスタムフィールドGET_CONTENT

<h2><span>my heading</span></h2> 

これは私の通常のWordpressのコンテンツでは正常に動作しますが、内のコンテンツ高度なカスタムフィールドは、それを取り除きます。誰もが何らかのアイデアを持っている - 何時間もグーグルで過ごした

//add span into each title so can add flourish under span 
add_filter('the_content', 'replace_content',1); 
function replace_content($content) { 
    $content = preg_replace('/<h(\d{1,6})(.*?)>(.*?)<\/h(\d{1,6}).*?>/', '<h$1><span>$3</span></h$4>', $content); 
    return $content; 
} 

多くのお手伝いをいただきありがとうございます。

答えて

1

私はそれを試していませんが、ACFはあなたが探しているかもしれないacf/load_valueフィルタを持っています。このフックを使用すると、データベースからロードされた直後にフィールドの値を変更できます。

function my_acf_load_value($value, $post_id, $field) 
{ 
    // run the_content filter on all textarea values 
    $value = apply_filters('the_content',$value); 

    return $value; 
} 

// acf/load_value - filter for every value load 
add_filter('acf/load_value', 'my_acf_load_value', 10, 3); 

// acf/load_value/type={$field_type} - filter for a value load based on it's field type 
add_filter('acf/load_value/type=select', 'my_acf_load_value', 10, 3); 

// acf/load_value/name={$field_name} - filter for a specific value load based on it's field name 
add_filter('acf/load_value/name=my_select', 'my_acf_load_value', 10, 3); 

// acf/load_value/key={$field_key} - filter for a specific field based on it's name 
add_filter('acf/load_value/key=field_508a263b40457', 'my_acf_load_value', 10, 3); 
documentationから

コード例

関連する問題