我的问题是keyword page analysis tool 不读取我的自定义字段,因此我正在尝试找出如何对其运行筛选器。
我在Yoast网站上找到了一篇博文here 其中引用了此问题,并列出了筛选器wpseo_pre_analysis_post_content
, 但我不确定如何在球场上运行。
我在上的管理编辑屏幕上找到了一个运行函数的操作ACF website : acf/input/admin_head, 但我不知道如何对已加载的操作运行筛选器。
编辑:
我发现acf插件实际上内置了这个过滤器,但似乎不起作用。
// set value
if( !isset($field[\'value\']) )
{
$field[\'value\'] = apply_filters(\'acf/load_value\', false, $post_id, $field);
$field[\'value\'] = apply_filters(\'acf/format_value\', $field[\'value\'], $post_id, $field);
apply_filters( \'wpseo_pre_analysis_post_content\', $field[\'value\'] );
}
SO网友:brasofilo
查看过滤器:
$post_content = apply_filters( \'wpseo_pre_analysis_post_content\', $post->post_content, $post );
这将是一个将字段内容添加到正在分析的字符串中的问题。
你必须做get_field()
部分正确,未经测试:
add_filter( \'wpseo_pre_analysis_post_content\', \'filter_yoasts_wpse_119879\', 10, 2 );
function filter_yoasts_wpse_119879( $content, $post )
{
$fields = get_field( \'name\', $post->ID );
return $content . $fields;
}
正如kaiser在评论中指出的
get_field()
功能不可靠。如果是一个相对简单的字段,那么最好坚持
get_post_meta
.
相关:Where do I put the code snippets I found here or somewhere else on the web?