I worked on a project recently where I needed to get the url of the current page dynamically then add it to a body class. The first part of this process was to retrieve the url. Here is how that is done with a WordPress site and with a Non WordPress site.
<?php | |
// Non WordPress | |
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; | |
// WordPress Site | |
global $wp; | |
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); |
Leave a Reply