Wordpress check if you're on the current page (not menu)


Staff member
I am creating a little shortcode that acts like the custom menu widget, but I'm choosing the pages from a dropdown list, instead of creating a menus inside the wordpress (I'm also adding a color to it, so I can't just use regular wordpress menus widget).

So far so good, it's just one thing that's bothering me. I want to check if the page I'm on matches the one in my list (on the real page). I googled and searched a bit and found that with

$actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

I can get the current page I'm on (the link I see in my browser). Perfect!

So if I want to add a class called current page, all I need to see if my
matches with my selected link from the dropdown list.

I'm working this within a page bulder plugin The Creator, so I know how to create a working shortcode in it. My pages dropdown is created by making an array that will have page url as key and page name as a value. My loop is:

$args = array (
    'post_type' => 'page',
    'posts_per_page' => -1,
    'orderby' => 'menu_order',
    'order' => 'ASC',
$pages = get_posts($args);

$forms = array();
    foreach ($pages as $page) {
        $forms[$page->url] = $page->post_title;

And it works perfectly. Except that the url I get from this is of the form:


Whereas I set my permalinks to be nice so the actual link in my browser is


The id is correct, and if I click on my 'menu' link I'll get to that page (desired result). But now I cannot just go and say:

$current = ($actual_link == $link) ? 'current_page' : '';

is the variable that holds the link to the page from the dropdown, so that I can append this to my list to check if I'm on the current page (adds a current_page class). I need this class for the styling purposes - if I'm on the page that has this menu shortcode, next to the link that matches this page I'll get chevron (>).

So my question is, how to get the matching urls, no matter what permalink setting I use? Is there a way to specify this in the
query, or with the

I am trying to avoid javascript with this one, and do everything server side.