wp_list_pages isnt showing title attribute

↘锁芯ラ 提交于 2019-12-23 02:36:29

问题


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');

回答1:


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.




回答2:


'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>',



回答3:


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>


来源:https://stackoverflow.com/questions/12353076/wp-list-pages-isnt-showing-title-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!