Show Current Archive Selected In WordPress

Hi Friends, Today I am starting new blog WordPress Addicted. I really love wordpress too much So I thoguht to start a new blog for only WordPress in which I will write about new code of wordpress, some solutions which creates problems for every wordpress developer and some new plugins which I will create with time in future.

So today my first post is related to WordPress Archive. WordPress Archive is used to get all posts from selected month, So when we click on any month we can see all posts posted in that month. But unlike menu of wordpress, clicked archive month not showing selected or not generating any class by which we can show clicked month selected. So to acheive this below are additional code which you need to add in function.php file anywhere.

function get_archives_link_mod ( $link_html ) {
preg_match ("/href='(.+?)'/", $link_html, $url);
$requested = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
if (trim($requested) == trim($url[1])) {
$link_html = str_replace("<li>", "<li class='current'>", $link_html);
return $link_html;
add_filter("get_archives_link", "get_archives_link_mod");</pre>

So just put this above code into your themes functions.php file, Now in above codem you can see we have added “current” class, So after adding this code in functions.php file you have to create one class “.current” in which you can use font color you want for selected archive or increase font size etc.. and then add that class to style.css file of your theme.

So this is the easiest way to show selected archive for your wordpress blog. Let me know if you cant understand or have any problem with this code. I will try to help you to solve your issues.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *