Custom link text wp_get_archive link

Im trying to create custom text for the archive links in my sidebar. Right now it prints it but it comes out as regular text - i'm trying to make the full text output into the link.

so "+ Trip {archive-link}" should be the link text

?php wp_get_archives( array( 'type' = 'yearly', 'before' = 'li class="CAPS source-bold"span class="plus"+/span Trip ','after' = '/li', 'format' = 'custom', ) ); ?

any help would be greatly appreciated!

Topic wp-get-archives Wordpress

Category Web


I think the simplest way would be to use the get_archives_link filter. For example:

add_filter ('get_archives_link',
function ($link_html, $url, $text, $format, $before, $after) {
    if ('with_plus' == $format) {
        $link_html = "<li class='CAPS source-bold'><a href='$url'>"
                   . "<span class='plus'>+</span> Trip $text"
                   . '</a></li>';
    }
    return $link_html;
}, 10, 6);

Then, in your template:

<?php wp_get_archives (['type' => 'yearly', 'format' => 'with_plus']) ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.