• I have a simple newbie question:

    I am using the Twenty Eleven theme and want to add a function to my child theme’s functions.php file.

    Right now, my child functions.php file has only the following lines in it:

    <?php
    /*
    adding second & third nav to child theme
    */
     register_nav_menus( array(
     'primary' => __( 'Primary Menu', 'twentyeleven-child' ),
     'secondary' => __( 'Secondary Menu', 'twentyeleven-child'),
     'third' => __( 'Third Menu', 'twentyeleven-child'),
     ) );
    ?>

    I want to add a function to this child functions.php file that will be a modification to the function “twenty eleven_posted_on()” that appears in the main (parent) functions.php file.

    What I want to know is simply this: do I add the modified function right below the code I have in functions.php already?

    In other words, can I simply add the code:

    function twentyeleven_posted_on() {
    …modified function code goes here...
    );

    Thank you.

    My site: http://roadslesstraveled.us

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can not have two same functions.
    If you think to add twentyeleven_posted_on() to child functions.php, you will have to delete it in parents functions.php

    Create function with different name, and in template where you call twentyeleven_posted_on(), call the new one like: twentyeleven_child_posted_on()

    Thread Starter hunter44

    (@hunter44)

    Thank you LapanWebsite.

    So are you saying that if I need to modify one of the theme’s functions so that whenever it is called (and I don’t know when or where it is called), the best way to do it is in the theme itself rather than in a child theme??

    Best way is to create new function, than if it is used, for example in single.php, than you copy single.php from parent theme to child, and open that child single.php which you copied, and you change:
    <?php twentyeleven_posted_on(); ?>
    With new one you made in childs functions.php:
    <?php twentyeleven_child_posted_on(); ?>

    This is just an example to direct you, I did not worked with that theme ever, so I don’t know its functions.

    You can do it in parent theme also, than you do not have to change template code, but it is not recommended here to change parent themes, and also, every new theme update will delete/reset your code.

    Hope that helps.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding a function to a child theme's functions.php file’ is closed to new replies.