Brutal Error. Header dissapear when i put the header folder in the child theme

Hi there,

When i put the into the child theme the folder with the header with the base file the header dissapear !

Hello @Almusan,

You may have added an incorrect or invalid code. What code did you add into the child theme? Would you mind providing the code in your next reply so that we an test it in our local testing sites?

Regards.

We have copypasted the following folder and it’s content from the parent theme to the child:

/wp-content/themes/x/framework/views/header/

We want to add custom code to the head but in this case the menu disappears before adding any custom code. Copypasting the folde without any modification on the files inside already makes the menu disappear.

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>
<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

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

    <div <?php echo $x_site_atts; ?>>

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

Hello @Almusan,

What kind of code you want to add to the head?

The most safest and easiest way of adding any JS and CSS scripts in the head is to install “Insert Headers and Footers” plugin. Once installed, simply go to Settings > Insert Headers and Footers and insert your code in the designated area.

If you are trying to insert a PHP code in the head, then the most appropriate way of doing that is to use the action hook. Assuming the child theme is set up, you can add the following code in your child theme’s functions.php file

function add_my_php_code(){
  // do something
  echo 'something to display here';
}
add_action('wp_head', 'add_my_php_code');

Hope this helps. Please let us know how it goes.

We don’t want to use any plugin to add simple code to the head, that’s terrible advice in terms of performance.

What we are trying to add is both basic html code and tag manager code. Anyway, regardless of the kind of code, we need to be able to add any element to the head from the child theme. That’s a basic requirement on any template.

The problem here is: there is a bug either in your child template or your parent template because when we COPYPASTE a folder from the parent theme into the child theme WITHOUT DOING ANY MODIFICATION the site layout breaks.

Please fix it as soon as possible.

Hi There @Almusan

I was able to experience this issue when tried to override the template files and I have reported this as a bug into our issue tracker for further review.

In the meantime, please use the alternative methods mentioned by @RueNel to integrate your custom codes.

Thanks for understanding!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.