【发布时间】:2019-04-08 01:47:12
【问题描述】:
我正在尝试使用 the_content 过滤器来处理 Divi 简码,但简码仍然出现。特别是 et_pb_section、et_pb_column、et_pb_text,如果这很重要的话。
add_action( 'rest_api_init', function () {
register_rest_field(
'post',
'content',
array(
'get_callback' => 'ap3_divi_do_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
register_rest_field(
'post',
'excerpt',
array(
'get_callback' => 'ap3_divi_do_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
});
function ap3_divi_do_shortcodes( $object, $field_name, $request ) {
global $post;
$post = get_post($object['id']);
// Set is_singular to true to avoid "read more issue"
// Issue come from is_singular () in divi-builder.php line 73
global $wp_query;
$wp_query->is_singular = true;
$output = array(
'protected' => false
);
switch( $field_name ) {
case 'content':
$output['rendered'] = apply_filters( 'the_content', $post->post_content );
break;
case 'excerpt':
$output['rendered'] = apply_filters( 'the_excerpt', $post->post_excerpt );
break;
}
return $output;
}
【问题讨论】:
-
您是否正在为 Divi 构建 GatsbyJS 无头前端?
-
我使用的是 AppPresser 插件。
标签: wordpress wordpress-rest-api