WordPress.org

Ready to get started?Download WordPress

Forums

Anchor Points only on post pages (2 posts)

  1. gamermatt0
    Member
    Posted 2 years ago #

    Hello,

    I have been researching anchor points, and how to make the page automatically scroll down to a given point on the page. Although, I am having some troubles.

    On each page, the URL ends with #video. And on every page that has a wordpress post, it automatically scrolls down to where I want it to. But, I only want the url to contain #video if it is a post page (not the index, about us, etc)

    I found this thread:
    http://wordpress.org/support/topic/move-page-down-on-load

    And so my header contains:

    <script type="text/javascript">
    
    function goToAnchor() {
    location.href ="#myAnchor";
    }
    
    </script>

    And:
    <body onload="goToAnchor();">

    Basically, I only want it to "onload="goToAnchor();" if the page is a page with a post on it. How would I go about doing this?

    Thanks

    Matt

  2. vtxyzzy
    Member
    Posted 2 years ago #

    I think this will work (UNTESTED). In the php file where the body tag is generated, try this code:

    <?php if (is_single()) : ?>
    <body onload="goToAnchor();">
    <?php else : ?>
    <body>
    <?php endif; ?>

    Also take a look at other conditional tags in the Codex:

    http://codex.wordpress.org/Conditional_Tags

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.