How to hook wp_list_pages?

How can I hook the wp_list_pages function so that it reads a value of a custom field and displays it instead of displaying the page title?

Solutions Collecting From Web of "How to hook wp_list_pages?"

A quick Google Search came up with this


Try the following:

function wp_list_pages_filter($output) {
    // modify $output here, it's a string of <li>'s by the looks of source
    return $output;
add_filter('wp_list_pages', 'wp_list_pages_filter');

A Walker Class extension would be necessary in this case:

class My_Custom_Walker extends Walker_page {
function start_el(&$output, $page, $depth, $args, $current_page) {
    if ( $depth )
        $indent = str_repeat("\t", $depth);
        $indent = '';

    extract($args, EXTR_SKIP);
    $output .= $indent . 
            '<li><div>' . get_post_meta($post_id, $key, $single) . '</div></li>';

} // End start_el
} // End Walker Class

Then, when you use your wp_list_pages function, you would call the class:

// Call class:
$My_Walker = new My_Custom_Walker();

$args = array(
    'walker'      => $My_Walker

wp_list_pages( $args );

Documentation on this subject is a bit scarce so let me know if you need more help.

You are able to pass in your own custom walker as one of the args, use this to pass in a walker which extends Walker_Page and uses your own custom post title.