我创建了一个名为“我的自定义设置”的元框,它位于 WordPress 中的帖子下,带有一个输入文本框字段。在该帖子页面的上面,我看到了带有预定义的“在屏幕上显示”的屏幕选项菜单。添加新的“我的自定义设置”元框后,它也可以在该屏幕选项中使用。
我刚刚隐藏了“我的自定义设置”。但似乎仍然处于邮寄状态。
为什么在隐藏屏幕选项时它不隐藏?
我的代码是,
<?php
add_action( 'add_meta_boxes', 'meta_add_custom_box' );
add_action( 'save_post', 'meta_save_custom_meta_box' );
function meta_add_custom_box( $post ) {
add_meta_box(
'Meta Box', // ID, should be a string
'My Custom Settings', // Meta Box Title
'meta_custom_meta_box_content', // Your call back function, this is where your form field will go
'post', // The post type you want this to show up on, can be post, page, or custom post type
'normal', // The placement of your meta box, can be normal or side
'high' // The priority in which this will be displayed
);
}
function meta_save_custom_meta_box(){
global $post;
// Get our form field
if( $_POST ) :
$meta_custom_meta = esc_attr( $_POST['meta-custom-meta-box'] );
// Update post meta
update_post_meta($post->ID, '_meta_custom_meta', $meta_custom_meta);
endif;
}
function meta_custom_meta_box_content( $post ) {
$meta_custom_meta = get_post_meta($post->ID, '_meta_custom_meta', true);
//meta title with character counting
echo '<p><label>Custom Title:</label></p>';
echo '<p><input style="width:99%;" class="meta-text" type="text" name="meta-custom-meta-box" value="'.$meta_custom_meta.'" /></p>';
}
?>
我是否需要添加额外的代码来隐藏屏幕选项?
如果是,请更新我的代码。
最佳答案
试试这个
add_filter('default_hidden_meta_boxes', 'hide_meta_lock', 10, 2);
function hide_meta_lock($hidden, $screen) {
if ( 'frog' == $screen->base )
$hidden = array('postexcerpt','Meta Box');
// removed 'postexcerpt',
return $hidden;
}
关于javascript - WordPress 中的屏幕选项不适用于新的自定义元框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23513504/