gelo.tv
Member
Posted 2 years ago #
I've posted before a question here but nobody has reply bynow: http://wordpress.org/support/topic/283092?replies=2#post-1114717
I need to add an anchor element to the link that return some wordpress funtions like posts_nav_link. I've a big header I want to add this anchor element to many internal links.
gelo.tv
Member
Posted 2 years ago #
OK, I finally decided to add a conditional autojump. This code will detect if the user is in home (where i want everybody to see and read the header content) and if there is already an anchor tag in the URL. If none of these conditions are true then it will jump to the defined anchor tag (where you've the main blog content, posts, etc.)
Hope this is useful for anyone using big headers:
<?php
global $anchor_var;
$Url="Http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; // get browser URL
$mystring = '#';
$pos = strpos($mystring, $Url); // detect if '#' is in the URL
if (($pos === false) && (is_home())) { // If there is no '#' and we are in the home page
$anchor_var = false;
} else {
$anchor_var = true;
}
?>
<?php if ($anchor_var) : ?>
<body onload="location='#YOUR_ANCHOR_TAG'"> // jump to the anchor
<?php else : ?>
<body> // don't jump
<?php endif; ?>
kcschaefer
Member
Posted 2 years ago #
Thank you so much! I had the same problem, and I used this script - perfect!