wordpress 后台取消显示custom fields(remove_meta_box)
2015-10-24 21:21
176 查看
在我们用wordpress做网站的时候,存储自定义数据,需要用到custom fields,也就是自定义字段。不过,我们在提供给用户使用后台的时候,不能向他们展示custom fields框,一是让用户理解这要怎么用会比较麻烦,二是没有一个友好的界面,使用起来并不方便。
所以,我们在默认情况下,是隐藏掉custom fields框的。
怎么取消掉呢,后台的custom fields框,也是一种meta box,在remove_meta_box函数里有介绍:
$id
(string) (required) Value of the id attribute of the HTML element to remove. Some of the available id values are given below:
‘authordiv’ – Author metabox
‘categorydiv’ – Categories metabox.
‘commentstatusdiv’ – Comments status metabox (discussion)
‘commentsdiv’ – Comments metabox
‘formatdiv’ – Formats metabox
‘pageparentdiv’ – Attributes metabox
‘postcustom’ – Custom fields metabox
‘postexcerpt’ – Excerpt metabox
‘postimagediv’ – Featured image metabox
‘revisionsdiv’ – Revisions metabox
‘slugdiv’ – Slug metabox
‘submitdiv’ – Date, status, and update/save metabox
‘tagsdiv-post_tag’ – Tags metabox
‘{$tax-name}div’ - Hierarchical custom taxonomies metabox
‘trackbacksdiv’ – Trackbacks metabox
…
所以,custom fields用remove_meta_box就可以隐藏,第一个参数换成‘postcustom’即可。
不过,函数使用的到时候,不能简单的在function里面添加这么一句,官方文档有相关实例:
要在action里使用才可以生效,
而且不要使用register_post_type里面的参数来取消custom fields的显示。
remove_meta_box
所以,我们在默认情况下,是隐藏掉custom fields框的。
怎么取消掉呢,后台的custom fields框,也是一种meta box,在remove_meta_box函数里有介绍:
remove_meta_box( $id, $page, $context );
$id
(string) (required) Value of the id attribute of the HTML element to remove. Some of the available id values are given below:
‘authordiv’ – Author metabox
‘categorydiv’ – Categories metabox.
‘commentstatusdiv’ – Comments status metabox (discussion)
‘commentsdiv’ – Comments metabox
‘formatdiv’ – Formats metabox
‘pageparentdiv’ – Attributes metabox
‘postcustom’ – Custom fields metabox
‘postexcerpt’ – Excerpt metabox
‘postimagediv’ – Featured image metabox
‘revisionsdiv’ – Revisions metabox
‘slugdiv’ – Slug metabox
‘submitdiv’ – Date, status, and update/save metabox
‘tagsdiv-post_tag’ – Tags metabox
‘{$tax-name}div’ - Hierarchical custom taxonomies metabox
‘trackbacksdiv’ – Trackbacks metabox
…
所以,custom fields用remove_meta_box就可以隐藏,第一个参数换成‘postcustom’即可。
不过,函数使用的到时候,不能简单的在function里面添加这么一句,官方文档有相关实例:
function remove_page_excerpt_field() { remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); } add_action( 'admin_menu' , 'remove_page_excerpt_field' );
要在action里使用才可以生效,
而且不要使用register_post_type里面的参数来取消custom fields的显示。
remove_meta_box
相关文章推荐
- wordpress rewrite问题解决
- WordPress升级版本及安装插件出现”Problem with the SSL CA cert”的解决办法
- 推荐十款免费 WordPress 插件
- 在Linux系统下一键重新安装WordPress的脚本示例
- Wordpress 忘记密码的处理方法
- cos-html-cache关于WordPress的静态化方法
- 关于bluehost空间上wordpress后台变为英文的解决方案
- 如何让PHPnow支持wordpress静态化链接的方法
- Wordpress ThickBox 点击图片显示下一张图的修改方法
- 将博客园(cnblogs.com)数据导入到wordpress的代码
- 完美实现wordpress禁止文章修订和自动保存的方法
- WordPress中is_singular()函数简介
- 使用wordpress的$wpdb类读mysql数据库做ajax时出现的问题该如何解决
- Wordpress php 分页代码
- WordPress中"无法将上传的文件移动至"错误的解决方法
- 在SAE上搭建最新wordpress的方法
- VPS中使用LNMP安装WordPress教程
- PHP+Memcache实现wordpress访问总数统计(非插件)
- PHP实现清除wordpress里恶意代码
- 再Docker中架设完整的WordPress站点全攻略