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

标签 javascript php jquery html wordpress

我创建了一个名为“我的自定义设置”的元框,它位于 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/

相关文章:

javascript - 单选按钮上的错误消息定位 JQuery 验证

javascript - Javascript 中的 UDP,用于本地主机上的进程间通信

javascript - d3.js 时间刻度图表,数组对象值不渲染图表,而静态值完美渲染图表

php - 如何从不同的行中获取唯一值

php - 为什么浏览器尝试下载我的 php 脚本文件?

jQuery Mobile 正在删除我的类

javascript - 尝试将工作表行数据发送到 GmailApp 时缺少变量名称; Javascript/Google 应用程序脚本

php - 使用 PHP 更改用户输入的背景图像

jquery - Bootstrap 图标不可见

jquery - Chrome "unable to load"图像作为 CSS 'background' - 然后它归咎于 jquery