Support » How-To and Troubleshooting » [Resolved] adding classes to wp_list_pages

[Resolved] adding classes to wp_list_pages

  • Hi 🙂 so I am trying to transform a regular div css layout to wordpress and I got everything working but am having problems with my page listing. I need to add a <a class= tag to the coding and i have no idea how to do that??? can it be done. My menu is in my header so i need it to be able to span across left to right instead of up and down.
    that is the basic code i use to call my pages but i have no idea how to add the a class tag to it without messing it up

    any help would be greatly appreciated.
    <?php wp_list_pages(‘sort_column=menu_order&depth=1&title_li=’); ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Add the following line to your theme’s functions.php template file, and it will add a class attribute of “tag” to each link generated by wp_list_pages():

    add_filter('wp_list_pages', create_function('$t', 'return str_replace("<a ", "<a class=\"tag\" ", $t);'));

    I know this thread was posted quite a while ago, but hopefully, filosofo, you’ll still check it.

    Is there a way, using that function, to specify which instances of wp_list_pages I want it to apply to?

    I have a menu in my header which uses wp_list_pages and “add_filter” is wonderfully adding a class to the anchor tags. However, in my sidebar I also have wp_list_page, but I do not want that particular list to have the class added. Is it possible to specify this? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] adding classes to wp_list_pages’ is closed to new replies.