I currently have availability

Hi, I'mKevin Shoffner

Customize your wp_get_archives() in WordPress

Usually I am very pleased with the WordPress community about how helpful they are with users who have questions.  Occasionally though, there is a question where for whatever reason people attack the user the question.

Thus I wanted to write about this one question/issue in particular because I have had multiple clients ask.  Although it’s not hard, it is not well documented at WordPress.

Have you ever been to a 404 WordPress page or even used a plugin/widget that displays Recent Posts using <ul> and <li> tags?
Have you ever wanted or wondered if this could be changed?  Great news, it can be.

If you are wanting to remove the <li> and </li> around your listing and customize the list, you are in luck.

In this tutorial I will cover how to take wp_get_archives and do some customization to it.

Open your 404.php or archive.php file and let’s get started.  Disclosure, I did use a Genesis child theme when doing this tutorial so if you see anything referring to Genesis, it’s not core to WordPress and my functions may be slightly different from what you see.

Okay, now you want to look near where your archive page has the header “Recent Posts” and you should see something like

Step #1

<?php wp_get_archives( 'type=postbypost&limit=100' ); ?>

Here you will want to modify the code by adding your modifications

format=custom  (this is required to take away the default format=html to be overwritten, and you now have two options.  A ‘before‘ and an ‘after‘ parameter.

Step #2

In my example I change the default

<?php wp_get_archives( 'type=postbypost&limit=100' ); ?>

to be

<?php wp_get_archives( 'format=custom&before=<p id="test">&after=</p>&type=postbypost&limit=100' ); ?>

Step #3

Now instead of a unordered list using <li></li>, the code will now be <p></p> and you are ready to go to town on customizations.  Endless possibilities.

I know this might be confusing with all of the code, so I’ve included a short video tutorial doing the same steps.

  • Theming Wordpress excerpts and archives – Koen Van Impe – vanimpe.eu | October 15, 2013

    […] http://kevinshoffner.com/wordpress/tipstricks/customize-wp_get_archives-wordpress/ […]

  • facklis
    facklis | March 4, 2014

    excellent stuff. most extensive wp_get_archives treatment found after plenty of searching.

    any idea how html (e.g., link to an archives page) can be appended to the output of the Archives (sidebar) widget in Genesis? struggling to do this within functions.php.

    • k.shoffner
      k.shoffner | March 7, 2014

      I would recommend looking at Genesis Simple Hooks as an option. This will keep you from messing with the themes function.php or other files too much

      • facklis
        facklis | March 7, 2014

        As a Genesis neophyte, didn’t know this plugin was out there. Really cool.

        Thanks for the suggestion!

  • MigsMigallos
    MigsMigallos | April 27, 2014

    Whoops, moderator, looks like the tags got formatted out of my reply. Sorry about that. Please just delete my comment to avoid confusion for future readers, and kindly review the posted code again. Tnx.

    • k.shoffner
      k.shoffner | May 5, 2014

      Thanks for your feedback, and I have adjusted accordingly as I did have a typo. I am not listing the old info, as it would probably cause some confusion, and have just adjusted the code within the Post.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: