get_archives_link

Retrieve archive link content based on predefined or custom code.

Description

(string) get_archives_link( (string) $url, (string) $text, (string) $format = 'html', (string) $before = '', (string) $after = '' ); 

The format can be one of four styles. The link for head element, option for use in the select element, html for use in list (either ol or ul HTML elements). Custom content is also supported using the before and after parameters.

The link format uses the HTML element with the **archives** relationship. The before and after parameters are not used. The text parameter is used to describe the link.

The option format uses the option HTML element for use in select element. The value is the url parameter and the before and after parameters are used between the text description.

The html format, which is the default, uses the li HTML element for use in the list HTML elements. The before parameter is before the link and the after parameter is after the closing link.

The custom format uses the before parameter before the link ('a' HTML element) and the after parameter after the closing link tag. If the above three values for the format are not used, then custom format is assumed.

Returns (string)

HTML link content for archive.

Parameters (5)

0. $url (string)
URL to archive.
1. $text (string)
Archive text description.
2. $format — Optional. (string) => 'html'
Optional, default is html.. Can be link,, option, html., or custom.
3. $before — Optional. (string) => ''
Content to prepend to the description. Default empty.
4. $after — Optional. (string) => ''
Content to append to the description. Default empty.

Usage

  1. if ( !function_exists( 'get_archives_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // URL to archive. 
  5. $url = ''; 
  6.  
  7. // Archive text description. 
  8. $text = ''; 
  9.  
  10. // Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. 
  11. $format = 'html'; 
  12.  
  13. // Optional. Content to prepend to the description. Default empty. 
  14. $before = ''; 
  15.  
  16. // Optional. Content to append to the description. Default empty. 
  17. $after = ''; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = get_archives_link($url, $text, $format, $before, $after); 
  21.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { 
  2. $text = wptexturize($text); 
  3. $url = esc_url($url); 
  4.  
  5. if ('link' == $format) 
  6. $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n"; 
  7. elseif ('option' == $format) 
  8. $link_html = "\t<option value='$url'>$before $text $after</option>\n"; 
  9. elseif ('html' == $format) 
  10. $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n"; 
  11. else // custom 
  12. $link_html = "\t$before<a href='$url'>$text</a>$after\n"; 
  13.  
  14. /** 
  15. * Filters the archive link content. 
  16. * @since 2.6.0 
  17. * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters. 
  18. * @param string $link_html The archive HTML link content. 
  19. * @param string $url URL to archive. 
  20. * @param string $text Archive text description. 
  21. * @param string $format Link format. Can be 'link', 'option', 'html', or custom. 
  22. * @param string $before Content to prepend to the description. 
  23. * @param string $after Content to append to the description. 
  24. */ 
  25. return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );