Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

hey guys, is it somehow possible to do the following:

wp_list_pages() lists each link inside a <li> <a href="link"...

<?php wp_list_pages('title_li=&depth=0&exclude='); ?>

Is it possible to add a #hash to those links? Like <a href="link#something"?

thank you for your help

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I'd wrap it in a function (save it in functions.php);

function wp_list_pages_with_hash( $hash, $args = '' )
    $add_hash = create_function( '$link', 'return $link . "#' . $hash . '";' );
    add_filter( 'page_link', $add_hash );
    $result = wp_list_pages( $args );
    remove_filter( 'page_link', $add_hash );
    return $result; // back compat in case 'echo' was null  

Then call it like so!

<?php wp_list_pages_with_hash( 'target', 'title_li=&depth=0' ); ?>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.