Jack
Jack

Reputation: 1

Show dofollow on homepage but hide on subpage

Using WordPress, I have two links in my Footer Widget.
One is a dofollow link and other is a nofollow link.

I need to display the dofollow on the homepage only, while the nofollow needs to be displayed on every subpage.

I’m wondering if this is possible with CSS, or if I need to use JQuery.

I’ve tried using the below code but have achieved nothing:

.footer-dofollow:is(.page-id-123) { display: none; }
.footer-nofollow:not(.page-id-123) { display: none; }

Any advice or feedback would be greatly appreciated.

Upvotes: 0

Views: 122

Answers (1)

Henfs
Henfs

Reputation: 5411

Since the page-id class is shown on body element usually, in CSS you can try this:

.page-id-123 .footer-dofollow {
  display: none;
}
.footer-dofollow {
  display: none;
}
.page-id-123 .footer-dofollow {
  display: inline;
}

Other way to make it is editing the widget .php file and checking if it is home page or not using is_home() function.

<?php if (is_home()): ?>
  <a href="example.com" class="footer-dofollow">Link</alt>
<?php endif; ?>

<?php if (!is_home()): ?>
  <a href="example.com" class="footer-nofollow">Link</alt>
<?php endif; ?>

You can also try to use is_front_page().

<?php if (is_front_page()): ?>
  <a href="example.com" class="footer-dofollow">Link</alt>
<?php endif; ?>

<?php if (!is_front_page()): ?>
  <a href="example.com" class="footer-nofollow">Link</alt>
<?php endif; ?>

Upvotes: 1

Related Questions