[resolved] adding classes to wp_list_pages (3 posts)

  1. randinicole
    Posted 7 years ago #

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

  2. Austin Matzko
    Posted 7 years ago #

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

  3. tronicscribe
    Posted 6 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.