Archived topic
Can't get child file in inc directory to override parent?
3 replies · Started by Ben on October 20, 2016
I've set up my GP child theme with this style.css:
/*
Theme Name: Generate Press Child
Template: generatepress
Text Domain: generate-press-child
*/
And this functions.php
<?php
function theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
?>
I'm trying to override inc/navigation.php file in the parent but when I recreate the file in my child theme it will not override.
Any help greatly appreciated.
I'm just trying to put some text to the left of my links in the main navigation menu.
Thanks
WN
I believe child themes can only overwrite files in the root directory.
That being said, overwriting anything in the inc folder is a bad idea, as future functions might be added in those files and called somewhere else, which would result in a fatal error if you were overwriting the file.
It might not be necessary in your case, as there's a hook that you can insert HTML into: generate_inside_navigation
Using hooks: https://generatepress.com/knowledgebase/hook-list/
Also, each function is wrapped in a function_exists() function, so you can grab the entire function (including the function_exists() part) and paste it into your functions.php file and that function will be overwritten.
Hope this helps :)
Cheers Tom,
That has helped, thanks.
All three bits of information are very useful to me, thanks again.
Ben
You're welcome :)