Title: Inserting permalink into wp_get_archives
Last modified: August 19, 2016

---

# Inserting permalink into wp_get_archives

 *  Resolved [raw-m](https://wordpress.org/support/users/raw-m/)
 * (@raw-m)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/)
 * Hi everyone
 * I’m trying to display the list of years with a custom background image specific
   to each year. I need a custom hook in the html for the css to get hold of.
 * I’ve customised wp_get_archives to strip out the default `<li>` and include a
   new one by changing the “format” to “custom” and using the before/after to include
   an `<li>` with a class (see below). Does anyone know if I can insert the permalinks(
   or any other attribute/php for that matter) into my class tag?
 *     ```
       wp_get_archives(array('format'=>'custom','type'=>'yearly','before'=>'<li class="PERMALINK HERE!">','after'=>'</li>
       '));
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758351)
 * If you can hand-code a couple of items to look the way you want, and paste the
   code here, I will try to generate that code from wp_get_archives() by exploding
   the string returned and preg_replacing selected parts.
 *  Thread Starter [raw-m](https://wordpress.org/support/users/raw-m/)
 * (@raw-m)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758405)
 * Hi vtxyzzy, many thanks for your offer
 * This is basically what I’m after (I’m not on my dev computer but the hrefs should
   be the same as is outputed by using wp_get_archives):
 *     ```
       <li class="2010"><a href="2010">2010</a></li>
       <li class="2009"><a href="2009">2009</a></li>
       <li class="2008"><a href="2008">2008</a></li>...
       ```
   
 * I’ve tried to recreate it using get_posts but I can’t find details on how to 
   return a list the same as “type=yearly”.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758406)
 * See if the code below will do what you want:
 *     ```
       $linkstring = wp_get_archives(array('echo' => 0,'format'=>'custom','type'=>'yearly','before'=>'|'));
       $linkarray = explode('|',$linkstring);
       if ( get_option('permalink_structure') != '' ) {
         $pattern = '#/(\d\d\d\d)/?[^>]+?>#';
       } else {
         $pattern = '/m=(\d\d\d\d)[^>]+?>/';
       }
       $output = "<ul>\n";
       foreach ($linkarray as $onelink) {
         if (preg_match($pattern,$onelink,$matches)) {
            $output .= "<li class='{$matches[1]}' >$onelink</li>\n";
         }
       }
       $output .= "</ul>\n";
       echo $output;
       ```
   
 *  Thread Starter [raw-m](https://wordpress.org/support/users/raw-m/)
 * (@raw-m)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758421)
 * vtxyzzy, you’re a star!! Massive thanks 🙂
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758430)
 * Glad it worked! Now, please use the dropdown at top right to mark this topic ‘
   Resolved’ so that anyone researching a similar problem can see that there is 
   a solution.
 *  Thread Starter [raw-m](https://wordpress.org/support/users/raw-m/)
 * (@raw-m)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758434)
 * It is done! Thanks again.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Inserting permalink into wp_get_archives’ is closed to new replies.

## Tags

 * [wp_get_archives](https://wordpress.org/support/topic-tag/wp_get_archives/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [raw-m](https://wordpress.org/support/users/raw-m/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-permalink-into-wp_get_archives/#post-1758434)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
