Overriding methods in a child theme

Guided by the Codex doc on Child Themes I have created a twentythirteen-child theme for my website by copying the unchanged index.php file from the parent theme and by creating this simple style.css file:

/*
 Theme Name:   Twenty Thirteen Child
 Theme URI:    http://example.com/twenty-fourteen-child/
 Description:  Twenty Thirteen Child Theme
 Author:       Alexander Farber
 Author URI:   http://afarber.de
 Template:     twentythirteen
 Version:      1
 Tags:         light, responsive-layout, accessibility-ready
 Text Domain:  twenty-thirteen-child
*/

@import url("../twentythirteen/style.css");

.site-header .home-link {
        min-height: 800px;
}

However since my website uses a custom header image I’ve also edited 2 files in WordPress –

1) I have changed the logo image height in the wp-content/themes/twentythirteen/inc/custom-header.php:

#'height'                 => 230,
 'height'                 => 800,

2) I have added #main anchor to the home-link in wp-content/themes/twentythirteen/header.php

<a class="home-link" href="https://wordpress.stackexchange.com/questions/152975/<?php echo esc_url( home_url("/#main' ) ); ?>"

I realize, that the core WordPress files shouldn’t be edited, because the changes will be overwritten and lost after the next WordPress version update.

But I don’t quite understand, how to put the 2 above changes in the functions.php suggested by the doc?

Could someone please give me some hints?

2 Answers
2

I would like to refer back to this answer on one of your previous questions about this subject. As said in that answer, you should never make changes to the twenty thirteen theme, and for that matter, to any theme/plugin you are not the author of, this includes core files as well.

But I don’t quite understand, how to put the 2 above changes in the functions.php suggested by the doc?

OK, you have your child theme set up, now you need to create a file in your child theme’s root and call it functions.php. Open this file and add an opening php tag (<?php) right at the top and press enter and save this file

For the first line of code, you can simply just change the custom-header arguments with this function

function my_custom_header_setup() {
    $args = array( 'height' => 800 );
    add_theme_support( 'custom-header', $args );
}
add_action( 'after_setup_theme', 'my_custom_header_setup' );

This will go into your child theme’s functions.php starting on line 2

For the second part, simply copy the twenty thirteen’s header.php file to your child theme’s root, open it up, make your changes and save it. Your child theme will now use this header.php instead of twentythirteen’s header.php. You can use this method for all other template files, except functions.php and functions.php related files, as you will trigger a fatal error. For example, if you need to make changes to index.php, simply copy it to your child theme, open it up, make your changes and save the file. Your child theme will then use this index.php, and not that of the parent

Leave a Comment