WordPress: Add Option, Text Field to General Settings Page

If you need to add an option to a site, but it doesn’t really need to be on its own page. You can probably add it to one of the existing settings pages. Here’s how to add an option to the General Settings page.

In this case, I’m adding a ‘Islamic Phrases’ field for my next WordPress plugin, probably not the best example, so go ahead and change that.

$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', 'Islamic_Phrases_Font_Size', 'esc_attr' );
        add_settings_field('Islamic_Phrases_Font_Size', '<label for="Islamic_Phrases_Font_Size">'.__('Islamic Phrases Font Size' , 'Islamic_Phrases_Font_Size' ).'</label>' , array(&$this, 'fields_html') , 'general' );
    function fields_html() {
        $value = get_option( 'Islamic_Phrases_Font_Size', '' );
        echo '<input class="small-text" type="text" id="Islamic_Phrases_Font_Size" name="Islamic_Phrases_Font_Size" value="' . $value . '" />&nbsp;px&nbsp;&nbsp;<span id="IsP_errmsg"></span>';


source: trepmal

Artikel terkait:   jQuery: Textbox Numbers Only

Isi Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

ninety nine − 91 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top