7

Span outside anchor tags I think you're looking for the before and after arguments (PHP 5.4+): wp_get_archives( [ 'before' => '<span>', 'after' => '</span>' ] ); if you want to wrap the <span> tag around the <a> tag: <li><span><a href="xx">Link text</a></span></li> ...


5

What you want can be done also filtering 'month_link' for monthly archives, 'year_link' for yearly archives and 'day_link' for daily archives. You can also write a function that extends wp_get_archives to work with CPTs, adding filters to 'getarchives_where' and to the archive link. function wp_get_cpt_archives( $cpt = 'post', $args = array() ) { // if ...


5

EDIT -> while this answer still works for < WP4.4, since 4.4 support for Custom Post Types is now included in wp_get_archives() There finally is a simple, quick and easy solution for date based archives of Custom Post Types in WordPress! This has been a long standing issue that is recorded here in the WP Core Trac. It has yet to be solved but one of the ...


3

You can use regular expression and the preg_replace_callback() function: function _make_khmer_link_replace_callback( array $matches ) { return '<a' . $matches[1] . '>' . convert_numbers_to_khmer( $matches[2] ) . '</a>'; } function make_khmer_link( $link ) { if ( get_bloginfo( 'language' ) == 'km' ) { $link = ...


3

Make use of custom parameter, lets call it wpse__current_year, which will accept two values, true (includes current year) and false (excludes current year). Lets incorporate that function show_monthly_archive( $post_type ) { $current_year_args = array( 'type' => 'monthly', 'limit' => '12', '...


3

There was a new function introduced in Wordpress 4.1 called the_archive_title() which does just that. You can simply add the_archive_title() in your archive page. If you need to filter the output, see my answer here on how to accomplish that


2

Can't add to takien's post so here's what I ended up having to do: functions.php add_action('init', 'my_year_archive_rewrites'); function my_year_archive_rewrites() { add_rewrite_rule('resource/news/([0-9]{4})/page/?([0-9]{1,})/?', 'index.php?post_type=news&year=$matches[1]&paged=$matches[2]', 'top'); add_rewrite_rule('resource/news/([...


2

The only filter i could find inside the wp_get_archives function is for displaying the links. Based on the get_archives_link filter, this should work, use it in your functions.php file: $archive_year = 0; add_filter('get_archives_link','wp_get_archive_grouped_by_year',10,2); function wp_get_archive_grouped_by_year($link_html) { global $archive_year; ...


2

If you look at wp_get_archives() you will notice that the link is generated by get_archives_link(). That function supplies a filter that will allow you to replace the parens. This is fairly crude but does work. function archive_link_wpse_183665($link) { $pat = '|\(([^)])\)</li>|'; // preg_match($pat,$link,$matches); // var_dump($matches); ...


2

Before I start again, I just want to reinforce the fact you should not run a custom query in place of the main query on your archive pages. Please see this post to learn when you should use a custom query and where not. I you do not switch back to the default loop, then my solution will not work In the previous post we have already solved the issue to only ...


2

It's not working because: You are redirecting home You don't listen for the $_GET variable so the archive link is just appended to your home url You need to add a function that listens for that $_GET variable. just add this to your functions.php file add_action( 'template_redirect', 'wpse_archive_select' ); function wpse_archive_select(){ if( isset( $...


2

Avoid using query_posts() Please don't use query_posts('posts_per_page=10'); in your date.php template file as it will override the main query instance and thus affect the main loop. This can truly ruin the day! If you need to modify e.g. the posts_per_page for the main date query, use the pre_get_posts action to modify the query variables, before the ...


1

I was going to suggest creating a regex to parse it but if you look at this comment on the Wordpress wp_get_archives() docs it looks like someone has gotten there before us.


1

Solution : "Add 'echo' => false, to the arguments array!" by @bcworkz different wp forum


1

According to the Template Hierarchy, archives are usually displayed using the theme's archive.php file, although other template pages might be used instead (see the image on that page). So, you would need to change your theme's archive.php file, or change the font-page.php or home.php template (again, see the image on the above page). I suspect that the ...


1

You can use post_type_archive_title( $prefix = '', $display = true ): <h1><?php post_type_archive_title() ?></h1>


1

Hey anyways I found with an exact answer which works as a charm. I hope it would be helpful to someone so I am posting it over here. First you need to add the following code in function.php /** * Custom post type date archives */ /** * Custom post type specific rewrite rules * @return wp_rewrite Rewrite rules handled by Wordpress */ ...


1

Your current code relies on time travel to work: $IDOutsideLoop = $post->ID; global $post; Specifically the first line is peering into the future, how can it know what $post->ID is if it's undeclared? The fix is global $post;, but when the computer gets to that line, it's too late global $post; $IDOutsideLoop = $post->ID; If you want to list ...


1

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> ...


1

As of WordPress 5.3, <a> elements generated by wp_get_archives (etc) for links to the current page have the attribute aria-current="page" added to them. If you just want to style the current page link differently, you can now target this with CSS, assuming you are happy for the styles to all be on the <a>: a[aria-current="page"...


Only top voted, non community-wiki answers of a minimum length are eligible