5ucms论坛
标题:
自定义插件删除REST API输出的标题中的p标签
[打印本页]
作者:
admin
时间:
2021-5-29 17:05
标题:
自定义插件删除REST API输出的标题中的p标签
在用wordpress作为小程序后台程序输出标题时,标题中带有p标签,无法在小程序中解析。 通过编写自定义插件,删除API输出的标题中的html标签
一、在wordpress的插件目录(wp-content/plugins)下新建myipsfan-wp-rest/myipsfan-wp-rest.php 文件
myipsfan-wp-rest.php内容如下:
增加了注释信息之后就可以在wordpress后台-插件里找到该插件,点击启用。(注意 插件名字要唯一)
<?php
/*
Plugin Name: myipsfan-wp-rest
Plugin URI: https://blog.ipsfan.com
Description: 删除REST API输出的标题中的p标签
Version: 1.0.1
Author: shine130
Author URI: https://blog.ipsfan.com
*/
function my_wp_rest_del_html($data,$post,$context){
$data->data['excerpt']['nohtmltitle'] = wp_strip_all_tags($data->data['excerpt']['rendered']);
return $data;
}
add_filter('rest_prepare_post','my_wp_rest_del_html', 10, 3);
复制代码
再次请求API,就成功在excerpt下增加了一个没有p标签的字段nohtmltitle了。 在小程序里用新字段调用即可
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2