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

代码示例

相关问题