wp_list_pages没有显示标题属性 [英] wp_list_pages isnt showing title attribute

查看:85
本文介绍了wp_list_pages没有显示标题属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上使用的是wordpress,并且由于某些原因wp_list_pages()没有显示标题属性?

我很想出于SEO的目的添加它.

有帮助吗?

我当前的代码是

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

解决方案

wp_list_pages()默认情况下不应该具有标题属性.如果给定的函数不符合您的需求,您可以始终编写自己的函数.

<?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;
  }
}
?>

将其放置在主题function.php中,并使用它代替wp_list_pages().如果您使用标准的wordpress主题,建议您为此创建一个子主题,因为主题更新会在将来删除您的更改.随时根据需要添加任何ID和类. 当您将诸如current_page_item之类的CSS类添加到当前生成的HTML标记中时,情况会变得更加复杂.

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

解决方案

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.

这篇关于wp_list_pages没有显示标题属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆