向wordpress设置常规页面添加固定字段
技术文章 2023年6月1日
通过向functions.php文件添加以下代码,就可以现实向wordpress设置常规页面添加固定字段
/**
* WordPress 添加额外选项字段到常规设置页面
*/
$new_general_setting = new new_general_setting();
class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'cuskeywords', 'esc_attr' );
add_settings_field('cuskeywords', '<label for="cuskeywords">'.__('关键词' ).'</label>' , array(&$this, 'fields_html') , 'general' );
}
function fields_html() {
$value = get_option( 'cuskeywords', '' );
echo '<textarea cols="60" rows="9" id="cuskeywords" name="cuskeywords" />' . $value . '</textarea>';
}
}
$new2_general_setting = new new2_general_setting();
class new2_general_setting {
function new2_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'cusaboutus', 'esc_attr' );
add_settings_field('cusaboutus', '<label for="cusaboutus">'.__('描述' ).'</label>' , array(&$this, 'fields_html') , 'general' );
}
function fields_html() {
$value = get_option( 'cusaboutus', '' );
echo '<textarea cols="60" rows="9" id="cusaboutus" name="cusaboutus" />' . $value . '</textarea>';
}
}