您不应该编辑核心文件,这会使升级非常困难。
使用add_meta_box()
函数并将其放入插件文件中。
请参见下面的示例,此插件将向wordpress安装中的所有页面添加一个元框。只需根据自己的方式进行编辑。。。
<?php
/*
Plugin Name: META Data Plugin
Plugin URI: http://eddsmith.me
Description: Adds a META description box to all pages.
Version: 1.0
Author: Edd Smith
Author URI: http://eddsmith.me
*/
?>
<?php
add_action(\'admin_init\',\'metadescription_meta_box_init\');
function metadescription_meta_box_init() {
// The Function that creates the meta box
add_meta_box(\'metadescription-meta\',__(\'META description\',\'metadescription-plugin\'), \'metadescription_meta_box\', \'page\',\'advanced\',\'default\');
// hook to save our meta box data when the page is saved
add_action(\'save_post\',\'metadescription_save_meta_box\');
}
function metadescription_meta_box($post,$box) {
// retrieve our custom meta box values
$metadescription = get_post_meta($post->ID,\'_metadescription\',true);
// custom meta box form elements
echo \'<p>\' .__(\'Enter META description below. Remember... <br/>#1 -Search engines truncate the description at 160 characters<br/>#2 - Leave blank and search engines will choose text for you<br/>#3 - Since 2009 META descriptions do not influence Googles ranking algorithms. \',\'metadescription-plugin\'). \': <input type="text" name="metadescription" value="\'.esc_attr($metadescription).\'" style="width:100%;"></p>\';
}
function metadescription_save_meta_box($post_id,$post) {
// if post is a revision skip saving our meta box data
if($post->post_type == \'revision\') { return; }
// process form data if $_POST is set
if(isset($_POST[\'metadescription\'])) {
// save the meta box data as post meta using the post ID as a unique prefix
update_post_meta($post_id,\'_metadescription\', esc_attr($_POST[\'metadescription\']));
}
}
?>