wordpress中的屏幕选项不适用于新的自定义元框

时间:2021-01-14 16:38:40

I have created a meta box named "My Custom Settings", it is under post in wordpress with one input text box field. In the above to that post page I have seen the screen options menu with predefined "show on screen". After adding my new "My custom settings" meta box, it also available in that screen options.

我创建了一个名为“我的自定义设置”的元框,它在wordpress中发布,带有一个输入文本框字段。在上面的帖子页面中,我看到了带有预定义“屏幕显示”的屏幕选项菜单。添加新的“我的自定义设置”元框后,它也可以在该屏幕选项中使用。

I have just hide that "My custom settings". But still it seems under post.

我只是隐藏了“我的自定义设置”。但仍然似乎在帖子之下。

Why its not hiding when hide on screen options?

隐藏在屏幕上的选项为什么它不隐藏?

My code is,

我的代码是,

<?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>';
}
?>

Whether I need to add extra code for screen options to hide??
If yes please update my code.

我是否需要为屏幕选项添加额外的代码来隐藏?如果是,请更新我的代码。

1 个解决方案

#1


1  

try this

 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;
 }

#1


1  

try this

 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;
 }