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?

  • Where is your custom field stored? – fuxia Feb 18 '12 at 11:48

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');
  • but how to replace the title by a custom field value ? – Mohamed Said Feb 17 '12 at 16:30
  • Title? Do you mean the Widget Title? That can be set by going to Dashboard -> Appearance -> Widgets and adding a Pages widget. You can customize the title there. – Zack Feb 17 '12 at 16:34
  • It is NOT an array of pages, it is a string. – mor7ifer Feb 17 '12 at 16:41
  • Would you please help :) – Mohamed Said Feb 17 '12 at 16:46
  • @m0r7if3r I see that now. – Zack Feb 17 '12 at 18:08

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.

  • I'm sorry but I just need some help code :) – Mohamed Said Feb 17 '12 at 16:50
  • What part of my implementation is not clear enough for you to write code? – mor7ifer Feb 18 '12 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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