0

I am trying to add a custom header navigation to a WordPress site using a child theme (I'm using the Alphabet theme). I determined that I am using the header1.php file according to the styling inside and the selection I made in the admin view. I copied the header1.php file from the parent theme to the child theme and added in a new div block. However, the new div is not showing up.

I have registered my new menu in the WP admin successfully and have created links for it, the CSS in the child theme style.css file is being loaded when I check the source tab in Google Chrome's dev tools, and I have activated the child theme in the admin. I also made sure to replicate the includes -> header_layout directories inside my child theme.

I'm not sure what I'm missing? I don't want to add the new navigation into the parent theme because it will be overridden whenever the theme is updated and that's a major inconvenience. Is there another way I could create the custom navigation perhaps?

Edit: At the bottom of the header.php file, there is this block of code that grabs the appropriate header content depending on what the user selects in the admin:

<div class="header">
      <div class="inner_header">
          <!-- Start Header Position -->
          <?php if(alphabet_get_option('header_position') == 'header1') { include ( get_template_directory() . '/includes/header_layout/header1.php'); } ?>
          <?php if(alphabet_get_option('header_position') == 'header2') { include ( get_template_directory() . '/includes/header_layout/header2.php'); } ?>
          <?php if(alphabet_get_option('header_position') == 'header3') { include ( get_template_directory() . '/includes/header_layout/header3.php'); } ?>
          <?php if(alphabet_get_option('header_position') == 'header4') { include ( get_template_directory() . '/includes/header_layout/header4.php'); } ?>
          <?php if(alphabet_get_option('header_position') == 'header5') { include ( get_template_directory() . '/includes/header_layout/header5.php'); } ?>
          <?php if(alphabet_get_option('header_position') == 'header6') { include ( get_template_directory() . '/includes/header_layout/header6.php'); } ?>
          <?php if(alphabet_get_option('header_position') == 'header7') { include ( get_template_directory() . '/includes/header_layout/header7.php'); } ?>
          <!-- End Header Position -->
      </div>
    </div> 
2
  • how does the parent theme load the file you are trying to override? many themes don't use the API correctly to allow a child theme to override.
    – Milo
    Commented Jun 10, 2016 at 15:51
  • See my edit above... Commented Jun 10, 2016 at 16:59

1 Answer 1

3

That edit explains it. Alphabet is poorly written. Its use of php's include rather than WordPress's own include functions like get_header and get_template_part is breaking the parent/child hierarchy. You could probably make a copy of the file header.php and change those includes, as long as the file calling in header.php does it correctly!

As long as alphabet_get_option returns just those valid values or something falsy this should fix it:

<div class="header">
  <div class="inner_header">
      <!-- Start Header Position -->
      <?php
      $header_layout = alphabet_get_option('header_position');
        if( $header_layout ) {
            get_template_part( 'includes/header_layout/' . $header_layout );
        }
      ?>
      <!-- End Header Position -->
  </div>
</div> 
4
  • I did not pick this terrible theme, and I cannot change to another one sadly. How could I change the includes? Sorry...I haven't used WordPress in years, and have only been finding tutorials for themes that are setup correctly.... Commented Jun 10, 2016 at 17:13
  • Edited to show how I'd try it, though I don't know how well the theme's functions behave of course. Was on my phone before which isn't easy for coding :-) Commented Jun 10, 2016 at 17:22
  • This worked! Thank you so much! I am not very familiar with WordPress anymore so I didn't realize this theme was poorly written (The person who selected this theme is not code-savvy at all). Now I have what to look for next time if I encounter this issue. Commented Jun 10, 2016 at 17:24
  • No problem! Glad it worked. Commented Jun 10, 2016 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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