wp_list_pages isnt showing title attribute

2019-06-06 16:10发布

I'm using wordpress on my site and for some reason the wp_list_pages() isn't showing a title attribute?

I'd love to add it for the SEO purposes.

Any help?

My current code is

wp_list_pages('depth=1&title_li=&exclude=9');

3条回答
叼着烟拽天下
2楼-- · 2019-06-06 16:42

Here is an example from the Wordpress codex.

In the following example, only Pages with IDs 9, 5, and 23 are included in the list and the heading text has been changed to the word "Poetry", with a heading style of :

   <ul>
<?php wp_list_pages('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
  </ul>
查看更多
男人必须洒脱
3楼-- · 2019-06-06 16:45

wp_list_pages() not supposed to have a title attribute by default. You can always write your own functions if the given functions don't fit your needs.

<?php 
function mytheme_list_pages($param) {
  $pages = get_pages($param); 
  foreach ( $pages as $page ) {
    $li  = '<li><a href="' . get_page_link( $page->ID ) . '" title="';
    $li .= esc_attr($page->post_title);
    $li .= '">';
    $li .= $page->post_title;
    $li .= '</a></li>';
    echo $li;
  }
}
?>

Place this in your themes function.php and use it instead of wp_list_pages(). If you are using a standard wordpress theme I recommend creating a child theme for this, since theme updates will remove your changes in the future. Feel free to add any ids and classes as you need them. It gets a little more complicated when you add css classes like current_page_item for the currently visible page to the generated HTML markup.

查看更多
乱世女痞
4楼-- · 2019-06-06 16:50

'post_title.'">%s%s%s',

add this code wp-includes/post-template.php  line number  1345

'<li class="%s"><a href="%s" title="'.$page->post_title.'">%s%s%s</a>',

查看更多
登录 后发表回答