0

This relates to this previously asked question.

I followed exactly the advice given but it doesn't seem to work?

The advice was: "Duplicate the header.php to header-{custom-name}.php, let's say (header-nonavfooter.php) then in the template file replace get_header() with get_header('nonavfooter'). In the new header file (header-nonavfooter.php) remove the code related to navigation."

At the top of the template I'd like to have no navigation or footer is this:

<?php
/*
* Template Name: No Navigation/ No Header
*/

if (!defined('ABSPATH'))
exit; // Exit if accessed directly
get_header('headerremoved');
?>

I created a file called headerremoved.php (with the removed navigation) but it still loads the navigation which suggests this template is loading the original header...

Very confused why it isn't working - is there something I should be looking for to problem-solve here?

+++

My headerremoved.php (named like that) is like this:

<?php
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
/**
* The Header for our theme
*
* Displays all of the <head> section and everything up till <div 
id="main">
*
* @package WordPress
* @subpackage
* @since 2015
*/
?><!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 7) & !(IE 8)]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
    <meta charset="<?php bloginfo('charset'); ?>">
    <meta name="viewport" content="width=device-width, initial-
 scale=1.0" />
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
    <!--[if lt IE 9]>
    <script src="<?php echo esc_url(get_template_directory_uri()); ?>/js/html5.js"></script>
    <![endif]-->

    <!-- GTM IC 20170805 -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','XXX');</script>

    <!-- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->

    <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">

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

<body <?php body_class(); ?>>
<!-- GTM IC 20170805 -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=XXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

<!-- navigation removed -->

The top of my template file looks like this:

<?php
/*
* Template Name: No Header
*/

if (!defined('ABSPATH'))
exit; // Exit if accessed directly
get_header('header-headerremoved');
?>
6
  • Try and remove the get_header() line completely. What happens?
    – Johansson
    Aug 10, 2017 at 0:02
  • It breaks the entire theme/ css... The strange thing is that I had it working but I renamed the file with the removed navigation and I can't recreate how to do it. I've checked multiple times for typo's etc
    – Henry
    Aug 10, 2017 at 0:08
  • Any chance of having a look into your headerremoved.php file? By the way, the file name should be header-headerremoved.php to work.
    – Johansson
    Aug 10, 2017 at 0:10
  • sure - thanks - i've updated the question to show the code
    – Henry
    Aug 10, 2017 at 0:19
  • I meant the file's name, not the call to it :) When you use get_header('header-headerremoved');, WordPress will automatically add a header- prefix, and look for the file. For example, it will look for header-header-headerremoved.php in your case. So, rename your file to header-headerremoved.php, and use get_header('headerremoved');
    – Johansson
    Aug 10, 2017 at 0:22

1 Answer 1

2

If you take a look into the codex page for get_header() function, you will notice that WordPress automatically adds a header- prefix to your call. For example, using this:

get_header('sample');

Will search for the header-sample.php file. So, in your case, you should name your header file header-headerremoved.php and then call it the following way:

get_header('headerremoved');

Your Answer

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

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