The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

[Solved] wp_list_pages to anchor

  • # October 1, 2009 at 10:23 pm

    Hi, I´m using this code to list only the subpages,

    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <?php echo $children; ?>
    <?php } ?>

    but I need them to go to a specific anchor call #menu

    Any Help?


    # October 2, 2009 at 6:42 am

    It’s not straightforward to do this as it involves using a filter to modify the page link.

    // Place this function in your theme’s functions.php
    function add_hash($link) {
    // this code adds a hash tag to the end of the link
    return $link . ‘#menu’;

    Then in your theme use this:

    add_filter(‘page_link’, ‘add_hash’);

    // .. your code to list subpages here

    remove_filter(‘page_link’, ‘add_hash’);

    # October 3, 2009 at 9:28 pm

    Nice It really works fine, thank you a lot.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed