0

I have a sidebar with links to 4 guides that I wrote... When users are reading one of my guides I only want to show them the links to the 3 other guides, so no link to the guide they are currently reading...

I built a PHP condition based on the current URL to only show links to the guides that the user is not currently reading. And I added that to the sidebar widget using "5sec run PHP"...

The problem is that plugin tends to conflict with other plugins and it does in this case also, so to use it is not an option for me...

So then my question becomes...

How else can I Conditionally Not Display a Link in the Sidebar Based on the Current URL?

What is the best and cleanest way to do what I want?

  • how are you putting this links? – Reigel Feb 12 '15 at 4:19
  • In a sidebar text widget. Just regular image links – Jan Paul Feb 12 '15 at 6:02
0

because you are using a text widget, this is what I can suggest you do...

if you have links like this on your widget,

<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="#">link 4</a>

you could add a class to it based on body classes. you can check yours in your browser by viewing page source. If your theme is well written, you should have something like postid-208 in your class of <body tag.

Now, with that we can add it to your links as class then make css to hide it. If you want link 1 to be hidden it that page, do it like this:

<style>
    .postid-208 .postid-208 {
        display: none !important;
    }
</style>
<a href="#" class="postid-208">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="#">link 4</a>

for others, I'll assume some class, then it would be like this...

<style>
    .postid-208 .postid-208,
    .postid-209 .postid-209,
    .postid-211 .postid-211,
    .postid-231 .postid-231 {
        display: none !important;
    }
</style>
<a href="#" class="postid-208">link 1</a>
<a href="#" class="postid-209">link 2</a>
<a href="#" class="postid-211">link 3</a>
<a href="#" class="postid-231">link 4</a>
  • Very interesting and simple solution! Would Google not view this as hiding links though? I mean they've spoken openly about taking action against people hiding links and such. – Jan Paul Feb 12 '15 at 7:00
  • P.S. the links do not necessarily need to be in a text widget, they can also be outside of any widget, but in the sidebar still. That would actually be the preferred solution. – Jan Paul Feb 12 '15 at 7:03
  • That's not really a problem. The link is owned by your site. Would google penalize dropdown menu? :D – Reigel Feb 12 '15 at 7:04
  • outside or inside widget, it's still the same. As long as it is inside <body tag.. – Reigel Feb 12 '15 at 7:05
  • Ok thanks alot, I will try it out soon and then come back to mark it as the solution – Jan Paul Feb 12 '15 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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