Wp_list_pages change page title on output

I am using wp_list_pages to create a submenu on a page and child page.
All working fine

My menu looks like
Parent, page title is Hello
Child,
Child,
Child,
etc

Read More

I am trying to find a way to dynamically change the Page title on output.
In my example above, I would like my Parent page to display GoodBye instead of Hello.

You might wander why I don’t just rename my page to Goodbye.
It is because the Page title , in my design, is displayed in 3 different format
– menu Header Hello displays Welcome (can change this via WP menu
– Page title display the correct title, ie Hello

I need my left menu to display Goodbye….

hope this makes sense for somebody

thx

Related posts

Leave a Reply

1 comment

  1. Use a custom field on your page…let’s call it sidebar_title.

    Then, you’ll need to convert your wp_list_pages code into a custom WordPress loop (there might be a way to use get_pages to do the same if you prefer that.

    Here’s some sidebar code to list the current page and it’s child pages, replacing the_title(); with your sidebar_title if it exists. It’s pretty ugly…the main point is to show you how to access custom fields.

    <?php
        //Get children of current page and display with custom fields. 
        //You will probably need to adjust this.
        $args=array(
          'post_parent' => $post->ID,
          'post_type' => 'page',
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
        ?>
        <ul>
        <?php 
            // Print parent with sidebar_title, if it exists
            $sidebar_title = get_post_meta($post->ID, 'sidebar_title', true); 
            if ($sidebar_title != ''){ ?>
                <li><a href="<?php the_permalink() ?>"><?php echo $sidebar_title;?></a></li>
            <?php } else { ?>
                <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
            <?php } ?>
        <?php
          // Print each child page with sidebar_title, if it exists
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <?php 
                $sidebar_title = get_post_meta($post->ID, 'sidebar_title', true); 
                echo $sidebar_title;
                if ($sidebar_title != ''){ ?>
                    <li><a href="<?php the_permalink() ?>"><?php echo $sidebar_title;?></a></li>
                <?php } else { ?>
                <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
                <?php } ?>
           <?php endwhile; } ?>
           </ul>
        <?php wp_reset_query();?>