user4577628
user4577628

Reputation:

How to remove breadcrumbs if “home” in wordpress static front page

I found this one Remove breadcrumbs if "home" in wordpress but sadly not working for me

<body<?php if(! is_home()) echo ' id="homepage"';?>>

in header.php

body#homepage#breadcrumbs {visibility: hidden;}

and added in style.css

Upvotes: 0

Views: 7428

Answers (6)

Aziz
Aziz

Reputation: 7793

CSS Update - it's .breadcrumbs not #breadcrumbs:

body#homepage .breadcrumbs { visibility: hidden; }

PHP:

<body<?php if(is_home()) echo ' id="homepage"';?>>

In your header.php code, the ! means NOT, therefore you're saying:

if NOT homepage, add id "homepage"

Which is the opposite of what you want.

Also note that visibility:hidden will hide the element but preserve its space in the layout.. if you want to hide the element and its space you can use display:none instead.

As @Eric-Mitijans explained, you have to add a space between body#homepage and #breadcrumbs otherwise you'd target a body tag with 2 IDs which is incorrect syntax.

Upvotes: 0

Rahul_Vijay
Rahul_Vijay

Reputation: 49

You can either use the if condition with home page id.

Upvotes: 0

TeeDeJee
TeeDeJee

Reputation: 3741

First change your css to this. Because Breadcrumb Trail uses a class of breadcrumbs and not an id.

body#homepage .breadcrumbs

Have you tried using is_frontpage() instead of is_home() ? Do you realize that at the moment you are adding homepage id to all pages which are not the "home" page? Don't use the ! in your if.

<body<?php if(is_frontpage()) echo ' id="homepage"';?>>
  • blog postspage = frontpage

    On the site front page:

    • is_front_page() will return TRUE
    • is_home() will return TRUE
  • static page = frontpage
    • On the page assigned to display the site front page:
      • is_front_page() will return TRUE
      • is_home() will return FALSE
    • On the page assigned to display the blog posts index:
      • is_front_page() will return FALSE
      • is_home() will return TRUE

Upvotes: 2

Touqeer Shafi
Touqeer Shafi

Reputation: 5284

There is another way to do it using body_class()

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

And then in the css if it's home page you can use

body.home #breadcrumbs { visibility: hidden; }

Upvotes: 1

Eric Mitjans
Eric Mitjans

Reputation: 2179

Also, the body has .home class in Wordpress by default.

So you can achieve it without the PHP part.

body.home #breadcrumbs{display:none;}

Upvotes: 1

Eric Mitjans
Eric Mitjans

Reputation: 2179

Try separating the #breadcrumbs.

In the CSS:

body#homepage #breadcrumbs {visibility: hidden;}

The code you posted refers to a body element with an ID breadcrumbs. What you need to target is an element with #breadcrumbs ID, that is inside a body with #homepage ID.

Upvotes: 1

Related Questions