Excerpt

Tuesday, November 8, 2016

Hide Wordpress header image on specific URL

Objective: Hide Wordpress header image on specific URL


Target URL: All URL except http://hilmanali.com/blog/


Theme: Sorbet (child)


File name: header.php


Original code:


<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
<?php do_action( 'before' ); ?>
<header id="masthead" class="site-header" role="banner">
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/blog' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="">
</a>
<?php endif; // End header image check. ?>
<div class="site-header-wrapper">
<div class="site-branding">
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/blog' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</div>

Modified code:


<body <?php body_class(); ?>>
<?php
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
$is_specific_network = stripos( $current_url, 'http://hilmanali.com/blog/page/' );
?>
<div id="page" class="hfeed site">
<?php do_action( 'before' ); ?>
<header id="masthead" class="site-header" role="banner">
<?php if( $is_specific_network !== false ) { ?>
<?php } else { ?>
<a href="<?php echo esc_url( home_url( '/blog' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="">
</a>
<?php } ?>
<div class="site-header-wrapper">
<div class="site-branding">
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/blog' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</div>

Screenshots:


2016-11-07_22_48_26

2016-11-07_22_49_05

2016-11-07_22_49_17

 

No comments:

Post a Comment