WordPress.org

Ready to get started?Download WordPress

Forums

How to add a theme option to Twenty eleven (7 posts)

  1. Marta
    Member
    Posted 2 years ago #

    I wanted to added a theme option to Twenty eleven theme. What I did was to add a form input at /wp-content/themes/twentyeleven/inc/theme-options.php, and it appears at back end, but when I "save" the value is not stored at database.

    I don't know what else I have to do.

    Thanks!

  2. First, please don't modify any of those files directly. When an update comes around you'll be really sorry and lose your edits. That would really suck.

    Create a child theme for Twenty Eleven inside a new directory called wp-content/themes/twentyeleven-child instead.

    Your new theme options should go into the child theme's functions.php file.

    Give this a read, the author of that post knows of what he speaks. ;)

    http://theme.fm/2011/07/how-to-create-a-child-theme-based-on-twenty-eleven-791/

  3. Marta
    Member
    Posted 2 years ago #

    Thank a lot! After read the information you gave me, I'm going to use child themes.

    But I have a doubt, for example in my theme child, I want to use the funcion "twentyeleven_theme_options_render_page()", what I should do?

    And I read I had to redefine it at child'functions.php, but if I do it I get an php error because a function can't be redeclared.

    Thanks again!

  4. But I have a doubt, for example in my theme child, I want to use the funcion "twentyeleven_theme_options_render_page()", what I should do?

    I couldn't find that function in twentyeleven/functions.php so you'll need to define it in your child theme's functions.php file.

    Try giving your copy a new unique name like zxoom_theme_options_render_page() and use that instead.

  5. Marta
    Member
    Posted 2 years ago #

    The function is inside parent theme: /inc/theme-options.php

    Try giving your copy a new unique name like zxoom_theme_options_render_page() and use that instead.

    But then I would have to modify parent theme in order to call the new function.

    The function: twentyeleven_theme_options_render_page() {
    The call at: twentyeleven_theme_options_add_page()

    Thanks!

  6. Ah, now I get where it is. We're good now.

    That one's tricky.

    If you look at line 92 of wp-content/themes/twentyeleven/functions.php you'll see this require() call

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

    The get_template_directory() returns the theme directory or the parent theme directory. It doesn't return the child_theme directory so yes, that copy is always loaded from the parent and not the child.

    Which I'm sure you know already, I'm just on one cup of coffee right now. ;)

    The only advice I can think of is to try to filter it via add_filter( 'twentyeleven_theme_options_render_page' , 'your_function' );

    And see if you can append or modify it via Konstantin's example in the link I provided.

  7. Marta
    Member
    Posted 2 years ago #

    Hi!

    Thanks a lot for your reply... I tell you what I finally did, I don't know if it is the best solution, but I had to rewrite functions for options theme.

    function replace_twentyeleven_theme_options_render_page () {
    remove_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );
    remove_action( 'admin_menu', 'twentyeleven_theme_options_init' );	
    
    add_action( 'admin_menu', 'twentyeleven_theme_options_add_page2' );
    add_action( 'admin_menu', 'twentyeleven_theme_options_init2' );
    }
    add_action( 'init' , 'replace_twentyeleven_theme_options_render_page' );

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.