如何在不创建插件的情况下在 wordpress 中创建自定义元数据框?

How can I create a custom metabox in wordpress with out creating plugin?

大多数情况下会创建一个插件和 metabox 的代码。它的代码非常冗长,并且无法在没有插件激活的情况下访问 metabox。每个站点的插件数量会降低站点的性能。请帮助

将以下代码粘贴到您在 word 中的活动主题的 function.php 中 press.it 将创建自定义元框:

/*Create custom MetaBox*/
function CreateTextfield()
{
$screen = 'post';
add_meta_box('my-meta-box-id','Text Editor','displayeditor',$screen,'normal','high');
}
add_action( 'add_meta_boxes', 'CreateTextfield' ) ;

/*Display PostMeta*/
function displayeditor($post)
{
global $wbdb;
$metaeditor = 'metaeditor';
$displayeditortext = get_post_meta( $post->ID,$metaeditor, true );  
?>
<h2>Secound Editor</h2>
<label for="my_meta_box_text">Text Label</label>
    <input type="text" name="my_meta_box_text" id="my_meta_box_text" value="<?php echo $displayeditortext;?>" />
   <?php        
}

/*Save Post Meta*/
function saveshorttexteditor($post)
{
$editor = $_POST['my_meta_box_text'];
update_post_meta(  $post, 'metaeditor', $editor);
}
add_action('save_post','saveshorttexteditor');

您可以通过以下代码创建和更新postmeta。您可以通过在 $screen.

中创建数组来添加屏幕