1

I'm fairly new to Wordpress. I'm using the shop-isle theme that has a default navigation menu. I'm trying to override this with a fancy ‘Ubermenu’ plugin but the default collapse symbol keeps overriding the plugin.

The theme header is loaded from directory shop-isle/inc/structure/header.php.

I copied the entire directory to my child theme directory and made edit below in /header.php but it only works when I add it to the 'structure' folder in the parent theme NOT the child.

example 1

<?php if( function_exists( ‘ubermenu’ ) ): ?>
  <?php ubermenu( 'main' , array( 'theme_location' => 'primary' ) ); ?>
<?php else: ?>
      <div class="header-menu-wrap">
        <div class="collapse navbar-collapse" id="custom-collapse">
          <?php
            wp_nav_menu(
                 array(
                    'theme_location' => 'primary',
                    'container'      => false,
                    'menu_class'     => 'nav navbar-nav navbar-right',
                       )
                    );
                        ?>
                 </div>
              </div>
<?php endif; ?>

I tried unhooking the function that loads the header but that removes the header all together!

The main header.php calls shop-isle/inc/structure/header.php. using

<?php do_action( 'shop_isle_header' ); ?>

The hooks.php located in shop-isle/inc/structure/hooks.php has the callback function registered using

add_action( 'shop_isle_header', 'shop_isle_primary_navigation',   50 );

I've copied all the files over to my child theme and kept the directory structure the same but it does not override the parent files.

How do I add the above code (example 1) in 'functions.php' in my child theme to update 'shop-isle/inc/structure/header.php'?

1

You need to copy to your child and edit the function where the file is included, probably ´shop_isle_primary_navigation´, to change the path where the file is located. Wordpress only loads automatically from child the default files, that's the ones defined in template hierarchy. You can read more about this at https://developer.wordpress.org/themes/basics/template-hierarchy/

0

You can't replace arbitrary theme files by adding them to your child theme. That will only work for files in the template hierarchy and files that the parent theme has explicitly allowed to be replaced. Please see my answer to a similar recent question for more on how child themes work.

To figure out exactly how to do what you want you should contact the theme author, but based on what you've posted so far it's possible to say that you need to first remove the original navigation from the header by using remove_action() with the same arguments originally used to hook it:

remove_action( 'shop_isle_header', 'shop_isle_primary_navigation', 50 );

Then in your child theme you need to create a new function in your child theme's functions.php file that outputs the header what you want:

function wpse_309907_primary_navigation() {
    if ( function_exists( ‘ubermenu’ ) ): ?>
        <?php ubermenu( 'main' , array( 'theme_location' => 'primary' ) ); ?>
    <?php else: ?>
        <div class="header-menu-wrap">
            <div class="collapse navbar-collapse" id="custom-collapse">
                <?php
                wp_nav_menu(
                array(
                'theme_location' => 'primary',
                'container'      => false,
                'menu_class'     => 'nav navbar-nav navbar-right',
                )
                );
                ?>
            </div>
        </div>
    <?php endif;
}

Then hook it in place of the original:

add_action( 'shop_isle_header', 'wpse_309907_primary_navigation', 50 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.