1

So basically, the 'Pages' widget just prints out a list of all pages names as links (as you all probably know).

Although, these anchor tags do not have any titles, and that is frowned upon in the SEO world.

I would like to modify this to have the titles simply as the name of the page.

For example, I would like to turn this:

<ul>
    <li class="page_item page-item-3307"><a href="http://www.domain.com/about-us/">About Us</a></li>
    <li class="page_item page-item-3315"><a href="http://www.domain.com/blog/">Blog</a></li>
    <li class="page_item page-item-100"><a href="http://www.domain.com/contact/">Contact Us</a></li>
</ul>

Into this:

<ul>
    <li class="page_item page-item-3307"><a href="http://www.domain.com/about-us/" title="About Us">About Us</a></li>
    <li class="page_item page-item-3315"><a href="http://www.domain.com/blog/" title="Blog">Blog</a></li>
    <li class="page_item page-item-100"><a href="http://www.domain.com/contact/" title="Contact Us">Contact Us</a></li>
</ul>

I have had a look around within the wp-includes/default-widgets.php file, although it is all pushed through a function called wp_list_pages.

What must I do to achieve this?

PS. Using Wordpress 3.8.1

2

A fast and short solution would be -

function wpse_list_pages( $output ){
    $output = preg_replace( '/<a(.*?)>(.*?)<\/a>/', '<a$1 title="$2">$2</a>', $output);
    return $output;
}
add_filter('wp_list_pages', 'wpse_list_pages');

And if you want a proper way, you could extend Walker_Page (ref: post-template.php) class and set the Pages Widget walker to class with widget_pages_args hook

| improve this answer | |

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.