WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

 
discard

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.