admin管理员组文章数量:1335587
I have created a sidebar:
function my_sidebar() {
register_sidebar(
array(
'name' => 'Blog Sidebar',
'id' => 'blog-sidebar',
'description' => 'Sidebar For Blog Page',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h5 class="widget-title">',
'after_title' => '</h5>'
)
);
}
add_action( 'widgets_init', 'my_sidebar');
I just added the "recent posts" widget and want to add a class to the <ul>
tag but I can't seem to figure out how to do it in a simple way. I just want the <ul>
tag to change to <ul class="link-list">
I have created a sidebar:
function my_sidebar() {
register_sidebar(
array(
'name' => 'Blog Sidebar',
'id' => 'blog-sidebar',
'description' => 'Sidebar For Blog Page',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h5 class="widget-title">',
'after_title' => '</h5>'
)
);
}
add_action( 'widgets_init', 'my_sidebar');
I just added the "recent posts" widget and want to add a class to the <ul>
tag but I can't seem to figure out how to do it in a simple way. I just want the <ul>
tag to change to <ul class="link-list">
2 Answers
Reset to default 1The quickest and practical solution for you would be to add your custom class to the before_widget wrapper:
'before_widget' => '<div class="widget ul-link-list">'
Then use CSS rules accordingly:
.ul-link-list ul {
/* Some CSS rules */
}
It's not possible to modify markup normally via actions/filters because markup is hardcoded in Wordpress \wp-includes\theme-compat\sidebar.php
So it's possible to change only via js, or php html output parsing
本文标签: functionsWhy is it so hard to add a class to the ltulgt tag in the sidebar widget
版权声明:本文标题:functions - Why is it so hard to add a class to the <ul> tag in the sidebar widget? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742384132a2464686.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论