[Resolved] Can't get child file in inc directory to override parent?

Home Forums Support [Resolved] Can't get child file in inc directory to override parent?

Home Forums Support Can't get child file in inc directory to override parent?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #237363
    Ben

    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

    #237420
    Tom
    Lead Developer
    Lead Developer

    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 ๐Ÿ™‚

    #237565
    Ben

    Cheers Tom,
    That has helped, thanks.
    All three bits of information are very useful to me, thanks again.
    Ben

    #237707
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.