2016-12-15 181 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

代碼示例

相關問題