Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jpajares

    (@gelotv-1)

    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; ?>

    Thank you so much! I had the same problem, and I used this script – perfect!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add an anchor element to the link returned by wordpress functions’ is closed to new replies.