• Hello.
    Does anyone know how to assign the “page_item” and “current_page_item” classes to the link (<a>) and not the list item (<li>). In essence, what I’m looking to end up with is the following…

    <li><a class="page_item current_page_item" href="https://mysite.com/?page_id=1" title="Title">Title</a></li>

    INSTEAD OF…

    <li class="page_item current_page_item"><a href="https://mysite.com/?page_id=1" title="Title">Title</a>

Viewing 1 replies (of 1 total)
  • *Without* editing the WordPress core? Here’s how:

    1. Add echo=0 to your wp_list_pages() parameters:

    <?php wp_list_pages('title_li=&echo=0'); ?>

    1.1. At the same time, make sure to pass wp_list_pages() to a variable:

    <?php $my_pages = wp_list_pages('title_li=&echo=0'); ?>

    2. Now for the PHP magic:

    <?php
    $my_pages = wp_list_pages('title_li=&echo=0');
    $my_pages = str_replace('<li class="page_item current_page_item"><a ', '<li><a class="page_item current_page_item" ', $my_pages);
    echo $my_pages;
    ?>

    3. And to move both class="page_item" and class="page_item current_page_item" from the <li> into the <a>:

    <?php
    $my_pages = wp_list_pages('title_li=&echo=0');
    $my_pages = str_replace('<li class="page_item"><a ', '<li><a class="page_item" ', $my_pages);
    $my_pages = str_replace('<li class="page_item current_page_item"><a ', '<li><a class="page_item current_page_item" ', $my_pages);
    echo $my_pages;
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘current_page_item on link’ is closed to new replies.