Wordpress theme options (Q)

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
Hi, i downloaded a wordpress theme with already have a theme option. I just want to add some option like allowing the user to update the footer text.

here is my current code in theme-options.php

PHP:
<?php

load_theme_textdomain( 'devdmbootstrap3', get_template_directory() . '/languages' );

/////////////////////////////////////////////////////////////////////
// Add DevDm Theme Options to the Appearance Menu and Admin Bar
////////////////////////////////////////////////////////////////////

    function dmbs_theme_options_menu() {
        add_theme_page( 'DevDm Theme' . __('Options','devdmbootstrap3'), 'DevDm' . __('Options','devdmbootstrap3'), 'manage_options', 'devdm-theme-options', 'devdm_theme_options' );
    }
    add_action( 'admin_menu', 'dmbs_theme_options_menu' );

    add_action( 'admin_bar_menu', 'toolbar_link_to_dmbs_options', 999 );

    function toolbar_link_to_dmbs_options( $wp_admin_bar ) {
        $args = array(
            'id'    => 'devdm_theme_options',
            'title' => __('DevDm Options','devdmbootstrap3'),
            'href'  => home_url() . '/wp-admin/themes.php?page=devdm-theme-options',
            'meta'  => array( 'class' => 'devdm-theme-options' ),
            'parent' => 'site-name'
        );
        $wp_admin_bar->add_node( $args );
    }

////////////////////////////////////////////////////////////////////
// Add admin.css enqueue
////////////////////////////////////////////////////////////////////

    function devdm_theme_style() {
        wp_enqueue_style('devdm-theme', get_template_directory_uri() . '/css/admin.css');
    }
    add_action('admin_enqueue_scripts', 'devdm_theme_style');

////////////////////////////////////////////////////////////////////
// Custom background theme support
////////////////////////////////////////////////////////////////////

    $defaults = array(
        'default-color'          => '',
        'default-image'          => '',
        'wp-head-callback'       => '_custom_background_cb',
        'admin-head-callback'    => '',
        'admin-preview-callback' => ''
    );
    add_theme_support( 'custom-background', $defaults );

////////////////////////////////////////////////////////////////////
// Custom header theme support
////////////////////////////////////////////////////////////////////

    register_default_headers( array(
        'wheel' => array(
            'url' => '%s/img/deafaultlogo.png',
            'thumbnail_url' => '%s/img/deafaultlogo.png',
            'description' => __( 'Your Business Name', 'devdmbootstrap3' )
        ))

    );

    $defaults = array(
        'default-image'          => get_template_directory_uri() . '/img/deafaultlogo.png',
        'width'                  => 300,
        'height'                 => 100,
        'flex-height'            => true,
        'flex-width'             => true,
        'default-text-color'     => '000',
        'header-text'            => true,
        'uploads'                => true,
        'wp-head-callback'       => '',
        'admin-head-callback'    => '',
        'admin-preview-callback' => 'devdm_admin_header_image',
    );
    add_theme_support( 'custom-header', $defaults );

    function devdm_admin_header_image() { ?>

        <div id="headimg">
            <?php
            $color = get_header_textcolor();
            $image = get_header_image();

            if ( $color && $color != 'blank' ) :
                $style = ' style="color:#' . $color . '"';
            else :
                $style = ' style="display:none"';
            endif;
            ?>


            <?php if ( $image ) : ?>
                <img src="<?php echo esc_url( $image ); ?>" alt="" />
            <?php endif; ?>
            <div class="dm_header_name_desc">
            <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
            <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>

            </div>
        </div>

    <?php }

    function custom_header_text_color () {
        if ( get_header_textcolor() != 'blank' ) { ?>
            <style>
               .custom-header-text-color { color: #<?php echo get_header_textcolor(); ?> }
            </style>
    <?php }
    }

    add_action ('wp_head', 'custom_header_text_color');

////////////////////////////////////////////////////////////////////
// Register our settings options (the options we want to use)
////////////////////////////////////////////////////////////////////

    $dm_options = array(
        'author_credits' => true,
        'right_sidebar' => true,
        'right_sidebar_width' => 3,
        'left_sidebar' => false,
        'left_sidebar_width' => 3,
        'show_header' => true,
        'show_postmeta' => true
    );

    $dm_sidebar_sizes = array(
        '1' => array (
            'value' => '1',
            'label' => '1'
        ),
        '2' => array (
            'value' => '2',
            'label' => '2'
        ),
        '3' => array (
            'value' => '3',
            'label' => '3'
        ),
        '4' => array (
            'value' => '4',
            'label' => '4'
        ),
        '5' => array (
            'value' => '5',
            'label' => '5'
        )

    );

    function dm_register_settings() {
        register_setting( 'dm_theme_options', 'dm_options', 'dm_validate_options' );
    }

    add_action ('admin_init', 'dm_register_settings');
    $dm_settings = get_option( 'dm_options', $dm_options );


////////////////////////////////////////////////////////////////////
// Validate Options
////////////////////////////////////////////////////////////////////

    function dm_validate_options( $input ) {

        global $dm_options, $dm_sidebar_sizes;

        $settings = get_option( 'dm_options', $dm_options );

        $prev = $settings['right_sidebar_width'];
        if ( !array_key_exists( $input['right_sidebar_width'], $dm_sidebar_sizes ) ) {
            $input['right_sidebar_width'] = $prev;
        }

        $prev = $settings['left_sidebar_width'];
        if ( !array_key_exists( $input['left_sidebar_width'], $dm_sidebar_sizes ) ) {
            $input['left_sidebar_width'] = $prev;
        }

        if ( ! isset( $input['author_credits'] ) ) {
            $input['author_credits'] = null;
        } else {
            $input['author_credits'] = ( $input['author_credits'] == 1 ? 1 : 0 );
        }

        if ( ! isset( $input['show_header'] ) ) {
            $input['show_header'] = null;
        } else {
            $input['show_header'] = ( $input['show_header'] == 1 ? 1 : 0 );
        }

        if ( ! isset( $input['right_sidebar'] ) ) {
            $input['right_sidebar'] = null;
        } else {
            $input['right_sidebar'] = ( $input['right_sidebar'] == 1 ? 1 : 0 );
        }

        if ( ! isset( $input['left_sidebar'] ) ) {
            $input['left_sidebar'] = null;
        } else {
            $input['left_sidebar'] = ( $input['left_sidebar'] == 1 ? 1 : 0 );
        }

        if ( ! isset( $input['show_postmeta'] ) ) {
            $input['show_postmeta'] = null;
        } else {
            $input['show_postmeta'] = ( $input['show_postmeta'] == 1 ? 1 : 0 );
        }

        return $input;
    }

////////////////////////////////////////////////////////////////////
// Display Options Page
////////////////////////////////////////////////////////////////////




		

    function devdm_theme_options() {

    if ( !current_user_can( 'manage_options' ) )  {
        wp_die('You do not have sufficient permissions to access this page.');
    }
	

        //get our global options
        global $dm_options, $dm_sidebar_sizes, $developer_uri;

        //get our logo
        $logo = get_template_directory_uri() . '/img/logo.png'; ?>

        <div class="wrap">

        <div class="dm-logo-wrap"><a href="<?php echo $developer_uri ?>" target="_blank"><img src="<?php echo $logo; ?>" class="dm-logo" title="Created by Danny Machal @ DevDm.com" /></a></div>

            <div class="icon32" id="icon-options-general"></div>

            <h2><a href="<?php echo $developer_uri ?>" target="_blank">DevDmBootstrap3</a></h2>

               <?php

               if ( ! isset( $_REQUEST['settings-updated'] ) )

                   $_REQUEST['settings-updated'] = false;

               ?>

               <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>

               <div class='saved'><p><strong><?php _e('Options Saved!','devdmbootstrap3') ;?></strong></p></div>

               <?php endif; ?>

            <form action="options.php" method="post">

                <?php
                    $settings = get_option( 'dm_options', $dm_options );
                    settings_fields( 'dm_theme_options' );
                ?>

                <table cellpadding='10'>
                
                                            

                    <tr valign="top"><th scope="row"><?php _e('Right Sidebar','devdmbootstrap3') ;?></th>
                        <td>
                            <input type="checkbox" id="right_sidebar" name="dm_options[right_sidebar]" value="1" <?php checked( true, $settings['right_sidebar'] ); ?> />
                            <label for="right_sidebar"><?php _e('Show the Right Sidebar','devdmbootstrap3') ;?></label>
                        </td>
                    </tr>

                    <tr valign="top"><th scope="row"><?php _e('Right Sidebar Size','devdmbootstrap3') ;?></th>
                        <td>
                    <?php foreach( $dm_sidebar_sizes as $sizes ) : ?>
                        <input type="radio" id="<?php echo $sizes['value']; ?>" name="dm_options[right_sidebar_width]" value="<?php echo esc_attr($sizes['value']); ?>" <?php checked( $settings['right_sidebar_width'], $sizes['value'] ); ?> />
                        <label for="<?php echo $sizes['value']; ?>"><?php echo $sizes['label']; ?></label><br />
                    <?php endforeach; ?>
                        </td>
                    </tr>

                    <tr valign="top"><th scope="row"><?php _e('Left Side Bar','devdmbootstrap3') ;?></th>
                        <td>
                            <input type="checkbox" id="left_sidebar" name="dm_options[left_sidebar]" value="1" <?php checked( true, $settings['left_sidebar'] ); ?> />
                            <label for="left_sidebar"><?php _e('Show the Left Sidebar','devdmbootstrap3') ;?></label>
                        </td>
                    </tr>

                    <tr valign="top"><th scope="row"><?php _e('Left Sidebar Size','devdmbootstrap3') ;?></th>
                        <td>
                            <?php foreach( $dm_sidebar_sizes as $sizes ) : ?>
                                <input type="radio" id="<?php echo $sizes['value']; ?>" name="dm_options[left_sidebar_width]" value="<?php echo esc_attr($sizes['value']); ?>" <?php checked( $settings['left_sidebar_width'], $sizes['value'] ); ?> />
                                <label for="<?php echo $sizes['value']; ?>"><?php echo $sizes['label']; ?></label><br />
                            <?php endforeach; ?>
                        </td>
                    </tr>

                    <tr valign="top"><th scope="row"><?php _e('Show Header','devdmbootstrap3') ;?></th>
                        <td>
                            <input type="checkbox" id="show_header" name="dm_options[show_header]" value="1" <?php checked( true, $settings['show_header'] ); ?> />
                            <label for="show_header"><?php _e('Show The Main Header in the Template (logo/sitename/etc.)','devdmbootstrap3') ;?></label>
                        </td>
                    </tr>

                    <tr valign="top"><th scope="row"><?php _e('Show Post Meta','devdmbootstrap3') ;?></th>
                        <td>
                            <input type="checkbox" id="show_postmeta" name="dm_options[show_postmeta]" value="1" <?php checked( true, $settings['show_postmeta'] ); ?> />
                            <label for="show_postmeta"><?php _e('Show Post Meta data (author, category, date created)','devdmbootstrap3') ;?></label>
                        </td>
                    </tr>

                    <tr valign="top"><th scope="row">Footer Text</th>
                        <td>

<?php
	$options[] = array(
		'name' => __('Footer Text', 'options_check'),
		'desc' => __('Add some info on the footer.', 'options_check'),
		'id' => 'footer_text',
		'std' => 'Some sample info',
		'type' => 'text');	
?>

                        </td>
                    </tr>

                </table>

                <p class="submit">
                    <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes','devdmbootstrap3'); ?>" />
                </p>

            </form>

        </div>
<?php

}
?>
i know i have to add this code inside my footer.php
PHP:
<?php echo devdmbootstrap3_get_option('footer_text','Enter some info here'); ?>
this is the screenshot
theme-opp.png


can you help me figure it out? :icon_rock:
 

CyberAlchemist

New member
Joined
Feb 9, 2013
Messages
245
Points
0
.....I just want to add some options like allowing the user to update the footer text.
Which extra options do you want to add to your footer template from codes above?

You should show which you want so that someone can help you out.
 

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
the footer text, i already added this code inside the theme-options.php but not showing.

PHP:
<?php
    $options[] = array(
        'name' => __('Footer Text', 'options_check'),
        'desc' => __('Add some info on the footer.', 'options_check'),
        'id' => 'footer_text',
        'std' => 'Some sample info',
        'type' => 'text');    
?>
 

savidge4

New member
Joined
Jan 6, 2016
Messages
121
Points
0
i can give you the answer or you can read this: http://codex.wordpress.org/Custom_Fields and maybe figure out where things are going wrong. Might I suggest looking at the inputs you already have on the page and working, and learn how to emulate those, but with a text box. (the 2 working elements are Checkbox and Radio )
 
  • Like
Reactions: ron13315

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
ron13315
can you show me your answer?

its really hard for me to figure it out.

this is what i did.
PHP:
<input type="text" id="dm_options[footer_text]" name="dm_options[footer_text]" <?php $dm_options['footer_text']; ?> />

the code i have inside my footer.php
PHP:
<?php if ($dm_options['footer_text'] == 1) { ?>
<?php echo $dm_options['footer_text'] ?>
<?php } ?>
 

elcidofaguy

Well-known member
Joined
Jan 13, 2015
Messages
1,281
Points
113
Hi Ron,

That's not the way I would amend the footer details as when you update the theme all of your modifications will be removed.

The way I do it is to setup a child theme and then copy the footer php file into that child folder with amending the footer code directly. In Wordpress all you need to do is activate your child theme....

In total it takes less than 5 minutes to set it up the way I explained...

For info on child theme setup check out this article. Personally I just do it the old way using a CSS file header only e.g.

1) Create a folder called 'ThemeName-child' in your themes folder noting to replace ThemeName with the name of your theme.


2) Create a new CSS file with the below code:

Code:
/*
 Theme Name:   Theme Name Child Theme
 Theme URI:      http://www.youthemeurl.com/
 Description:     Your Theme Description
 Author:           Your Themes
 Author URI:     http://www.whatitis.com
 Template:       Theme Name
 Version:         1.0.0
*/
 
@import url("../ThemeName/style.css");
 
/* =Theme customization starts here
i.e. Use your original theme's CSS code to populate the above and make sure to reference the correct @import url


3) Copy your the footer.php from your original theme to the child theme folder and change the footer URL directly.

4) Go into WP and activate your new child theme. Everything should work the way you want it too - and best of all you can update your theme without breaking the changes you made!


Hope that helps!
 

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
Hi sir @elcidofaguy, correct if im wrong. i read the article you mentioned, it said

A child theme consists of at least one directory (the child theme directory) and two files (style.css and functions.php), which you will need to create.

but since you mention that i can copy my footer.php to child theme then i can just duplicate my theme and rename it as themename-child so i can preserved all modification in all templates.

sorry for the late response. i just finished my theme and i think creating the child theme is the last thing i need to do.
 
Newer threads
Recommended threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top