Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fillter the current URL on subpages WordPress

EDIT: I am searching for a solution myself and the best I have come up with is the following type of script:

- First, check if the current URL looks like this (where XXX is a random string and Y is a random number)
- After that use to add the class "current-menu-item" to all menu items with pointing to

This should, at least partially, solve the problem and I think it is also easier to do.


Hi everyone,

I think, that this should be easy for people with some php knowledge. We are working on a site which relies on the current page marker and displays a couple of menus depending on it. It works fine, but we have a problem with pagination on archive pages. While the current menu item is detected properly on the first page of the archive, for example:

it breaks as soon as one moves to the second paginated page. Pagination uses the following structure:

What I need is a filter which changes the current menu item url for


(XXXX will vary, we use a couple of different taxonomies and post types).

Thanks in advance!


Answers (2)


Arnav Joy answers:

so you do not want pagination?

Yavor Trampov comments:

I do want pagination to work, URL should also stay the same. The only thing that needs to change is that

should be equal to

<strong>when comparing to the menu structure in order to attach the current menu item class only.</strong>

So, in menus on the menu item for should have the class .current-menu-item

Arnav Joy comments:

can you share url of your site?


Duncan O'Neill answers:

Hi there,

in theory, the menu item for should have the class current_page_ancestor. If that's the case, then all you'd need to do is update the css in your theme's style.css page. Find references to .current-menu-item, and add another css selector to that declaration. e.g;

.current-menu-item {font-weight:bold;}

would become

.current_page_ancestor {font-weight:bold;}

I can do this for you if you want to message me with FTP details.


Yavor Trampov comments:


unfortunatelly this is not the case, but here's a bit more info - started digging into this and realized, that I missed quite a few things.

We are using two plugins to extend the basic functionality of wp_na_menu:
This is just FYI - I turned both of them off to test and the result was the same.

What happens in my opinion - WP is changing the ?paging=2 to /page/2/ based on permalinks settings. Thus, on terms of comparint to menu items the page is completly new. What we need to do is filter the URL before it gets compared to menu items and remove the pagination attributes. I think, that this is a similar solution, but I could not get it to work:

I uploaded the example to a staging server, so you will be able to see it better. This is the archive page:

At the top, the text "Presse" and the links below it are actually the current branch of the main menu. When you click on the pagination links at the bottom, you see that this menu disappears. The URL changes to This is what I am trying to avoid.

Duncan O'Neill comments:

Do you have a paged.php file in your theme folder? If so, try renaming it, to paged.bak.php, or whatever. Does that fix the problem?

Duncan O'Neill comments:

Just a bit more information re the above reply. Referring to this [[LINK href=""]]template hierarchy diagram[[/LINK]] it looks possible, if not likely, that and are being controlled by two different files.