Longtime reader of stackoverflow but first question.
I\'m working with Wordpress (specifically thesis theme) in the custom_functions.php file and am finding for some
You do realize this is the default behavior, right? if you add /something the results would be different.
you can do a number of things to prevent default behavior.
href="#"
:Will do nothing but anchor - not the best solution since it may jump to page top.
<a href="#">
href="javascript:void(0);"
Will do nothing at all and is perfectly legit.
<a href="javascript:void(0);"></a>
href="your-actual-intended-link"
(Best)obviously the best.
<a href="<your-actual-intended-link>"></a>
If you don't want an a
tag to go somewhere, why use an a
tag at all?
You can just put // in front of $yourUrl in href:
<a href="//<?=$yourUrl?>"></a>
Add http:// in front of url
Incorrect
<a href="www.example.com">www.example.com</span></p>
Correct
<a href="http://www.example.com">www.example.com</span></p>
Use this:
<a href="<?php echo(($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); ?>">Whatever</a>
It will create a HREF using the current URL...
A solution that works no matter if you are developing on a local server or live is to add "//" in front of your link. This will effectivly remove the URL of the site you are currently on.
Example:
<a href="www.google.com">Google.com</a>
This will in output http://localhost/mySite/currentPage/www.google.com
What you should do instead is this:
<a href="//www.google.com">Google.com</a>
This will output www.google.com
In any case, your code will generate invalid markup: You shouldn't wrap block contents in a link. tags don't work like this. If you want this effect you should use js or create an absolutely positioned link above the content (z-index). More on this here: Make a div into a link.
You should make sure to validate your code when it renders: http://validator.w3.org