Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Hide a link conditional by its url



4:22 am on Sep 2, 2004 (gmt 0)

10+ Year Member

Hi all
Is it possible to hide an ahref link with php conditional on what the url is?
I use an off the shelf CMS that will only allow searching pages if the parent category is published as "visible". I don't want the parent category link in the navigation though so I was wondering if PHP could hide the link, maybe conditional on what the link (URL) is.


11:00 am on Sep 2, 2004 (gmt 0)

10+ Year Member

How bout righting into the script that makes it visible or invisible a new robot.txt? As long as its a respectible search engine if it says dont search it wont search.


11:18 am on Sep 2, 2004 (gmt 0)

WebmasterWorld Senior Member trillianjedi is a WebmasterWorld Top Contributor of All Time 10+ Year Member


I have a coder building a similar thing as we speak. StickyMail me in a week or so if you haven't found an alternative solution by then and I'll send you the code.

What I'm having built is something that logically works like this:-

1. If the link is to my domain, then echo out the straight link including any requested anchor text, e.g.:-

<a href="http://trillians/widgets.html">Trillian's Widgets</a>

Get's echoed out as it is.

2. If the link is not on one of my domains then echo out the link preceeeded with "http://mydomain/redirect.php?url=" and leave the rest (so anchor text is the same), eg:-

<a href="http://someone-else/widgets.html">A N Other's Widgets</a>

gets echoed out as:-

<a href="http://trilian/redirect.php?url=http://someone-else/widgets.html">A N Other's Widgets</a>

This is for a forum (tracking outbounds), but it would work for what you need to do, you would just need to edit it to echo out nothing if the URL matches the URL that you want to supress.


PS Welcome to Webmasterworld!


10:05 pm on Sep 2, 2004 (gmt 0)

10+ Year Member

Thanks TJ
Looks like it's exactly what I need. As soon as it's sorted I'd love to check out the code if possible.
Thankyou very much.


6:01 pm on Sep 4, 2004 (gmt 0)

10+ Year Member

This is what I did.
In any template I want to hide a specific link (in this case "Toolkit")I put the following at the top of the page:

<?php $hidePage="Toolkit";?>

I use the following css:

#hidden {display: none;}

Then in the nav:

<div<?php if ($hidePage=="$cat_name$")
echo " id=\"hidden\"";?>><a href="$url_index$">$cat_name$</a></div>

$cat_name$ is the placeholder in my CMS that dynamically populates the navigation. The PHP code will find the item "Toolkit" and wrap it with the css #hidden class.


5:22 pm on Sep 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

looks like that'll work well enough - except you might want to use single quotes, double quotes could put php into a parsing mode where it wants to get a variable with the name $cat_name$ (dunno, might not with that $ at the end, but single quotes would be safer, not to mention faster) -- you sure you want to hide it though with css? Maybe se's get suspicious? You can just not output it in the first place.

if($hidepage <> '$cat_name$') echo '<a href="$url_index$">$cat_name$</a>';

A second thought - this depends on how your templating thingie works, if it buffers the output and then replacing or replacing as it goes - if it's replacing as it goes, it'd probably be more like

if($hidepage <> $cat_name$) echo '<a href="'.$url_index.'">'.$cat_name.'</a>';


Featured Threads

Hot Threads This Week

Hot Threads This Month