WordPress.org

Forums

[resolved] Overriding twentyeleven theme-options.php (15 posts)

  1. sjsobol
    Member
    Posted 3 years ago #

    In twentyeleven's functions.php, this chunk of code loads the admin theme options...

    // Load up our theme options page and related code.
    require( dirname( __FILE__ ) . '/inc/theme-options.php' );

    The problem is that I'm creating a child theme, and this code will always load theme-options.php from /wp-content/themes/twentyeleven/inc.

    I'd like a workaround that doesn't involve modifying twentyeleven, but I don't think one exists.

    This is, at best, a bad design decision, and, at worst, an outright bug. Do you have a Bugzilla or Trac site, or another place where I can report this problem?

    Thanks

  2. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    WordPress bug reports:
    http://trac.wordpress.org

    But this is a deliberate design decision, and not a bug. Child Themes should not be expected to recreate the entire Theme Options functionality. It is normal, expected behavior to use the Theme Options from the Parent Theme.

    What is it that you're trying to do, exactly? There is very likely a workaround that does not involve modifying Twenty Eleven directly.

    For example, if you merely want to add an additional Theme Option to your Child Theme, you simply need to hook an add_settings_field() call into admin_init. If you want to add an entire section, call add_settings_section(), and then tie your add_settings_field() calls into your newly created section.

    If you need help with this, let me know.

  3. sjsobol
    Member
    Posted 3 years ago #

    I just want to get rid of the theme options page entirely. None of the options for twentyeleven are applicable to my theme.

    Can I unregister the theme options page? I already do that with the widget areas (unregister the ones that were registered by twentyeleven, then I register one of my own).

  4. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    The Twenty Eleven Theme settings are registered via register_setting(), so you could try calling unregister_setting().

    However, you'll have to account for all of the Theme Settings that are used in the functional and template files for the Theme. This change would be non-trivial.

  5. sjsobol
    Member
    Posted 3 years ago #

    I can't believe no one took into account that this situation might occur. I will have to stick with my current workaround for now (modifying the parent's files), but what exactly is the point of having a child theme if I do that?

  6. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    I can't believe no one took into account that this situation might occur.

    Your use case is far too much of an edge case to have been accounted for.

    In fact, I'm starting to think that you should be creating your own derivative Theme, rather than creating a Twenty Eleven Child Theme. If you're going to strip out the Theme options, then you're going to need to rewrite a considerable amount of Theme code, to replace the usage of the Theme options.

    What benefit do you gain from using a Child Theme? Why are you trying to use a Child Theme?

    Or, if you want to create a Child Theme that doesn't have Theme options, you should probably use as a Parent, a Theme that doesn't have Theme options.

  7. sjsobol
    Member
    Posted 3 years ago #

    Maybe you're right.

    Creating a child theme is a BCP, as noted in the WordPress documentation, and I figured "why re-invent the wheel?" But maybe I just need to make this a standalone theme.

    In fact, I just removed the line

    Template: twentyeleven

    from my style.css, and the theme is still working perfectly. So, yes, I'm thinking that that is the solution.

    Thanks

  8. andymacleod
    Member
    Posted 3 years ago #

    Child themes introduce extra code, making default code redundant. This is okay for minor changes. However, logically there comes a point where the changes are so major that it defeats the point of using a particular parent as the framework on which to build...

  9. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Creating a child theme is a BCP, as noted in the WordPress documentation

    Using a Child Theme is a best practice for certain use cases. Child Themes are fantastic for making CSS changes, for applying/removing filters, for adding custom template files, or for ad-hoc overriding of various template-part files (footer.php, etc.). These use cases cover perhaps 90% of Theme-modification needs, and as such, using a Child Theme is a best practice for such use cases.

    However, if you want to make a fundamentally different Theme, such as wholesale removal of Theme options, using a Child Theme is far less beneficial, and becomes less and less of a best practice.

    As you've discovered: you very well may end up creating more, rather than less, headaches for yourself.

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    I just removed the line
    Template: twentyeleven
    from my style.css, and the theme is still working perfectly.

    If you're going to create a standalone theme, you'll need to copy the entire contents of twentyeleven folder over to your new theme. Then edit style.css to reflect your new theme name.

  11. mtpultz
    Member
    Posted 3 years ago #

    I was trying to do the same thing and I found this solution just drop it in functions.php.

    <br />
    /**<br />
     * Cleanup parent theme options, widgets and custom header defaults<br />
     */<br />
    add_action( 'after_setup_theme', 'ask_twentyeleven_cleanup', 11 );</p>
    <p>ask_twentyeleven_cleanup() {<br />
      // Remove support for theme options<br />
      remove_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );<br />
    }<br />

    I ended up stripping down the theme quite a bit as more of a learning experience. Figured out how to remove custom background, unregister sidebars, widgets (like Ephemera). After reading this I've decided to do away with the child theme concept and instead try building a theme using what I've learned from Twenty Eleven. Pick and choice what I want instead of hacking and slashing what I don't. Especially since I can't figure out how to remove Display Text and Text Color from the options on the admin Header page.

    Maybe too late but hope this snippet helps someone. Cheers

  12. global_1981
    Member
    Posted 3 years ago #

    Thanks @mtpultz works perfectly...

  13. 5amsan
    Member
    Posted 3 years ago #

    For example, if you merely want to add an additional Theme Option to your Child Theme, you simply need to hook an add_settings_field() call into admin_init. If you want to add an entire section, call add_settings_section(), and then tie your add_settings_field() calls into your newly created section.

    I'm not sure this is documented somewhere, so let me ask for some more informations about it.
    What I'm trying to do is simply add a field to Twenty Eleven options page from my Twenty Eleven child theme.
    here's the piece of code:

    <?php
    add_action('admin_init', 'sbg_settings_api_init');
    function sbg_settings_api_init() {
    	add_settings_field('sbg_setting_test',
    			'SBG setting test',
    			'sbg_setting_field_render_test',
    			'theme_options',
    			'general');
    	register_setting('theme_options',
    			'sbg_theme_options',
    			'sbg_theme_options_validate');
    }
    
    function sbg_setting_field_render_test() {
    	$options = get_option('sbg_theme_options');
    	?>
    	<input type="text" name="sbg_theme_options[test] " value="<?php echo $options['test'] ?>" />
        <?php
    }
    ?>

    The problem is it can't save anything... Any light welcome.

    Cheers.

  14. Digital Raindrops
    Member
    Posted 3 years ago #

    Hi,
    If you want to remove the admin page then just use the code from mtpultz, copy the twenty eleven files across the the child add your options and load your page.

    If you were to add aditional settings to the twenty eleven theme options in code you would still need to display them on the options page, as the options page is not dynamic this makes it hard to do.

    What I tend to do is leave it 'as is' and just create a new 'theme setup' page of my own for my options, like in this downloadable one that has a page for the Flex Slider.

    HTH

    David

  15. 5amsan
    Member
    Posted 3 years ago #

    OK, so it's hard to do.
    I'll officially give up to add settings and create a new options page.

    Thanks for advice.

    PS. very impressive list of options on your Flex Slider integration.

Topic Closed

This topic has been closed to new replies.

About this Topic