I'd like to add a query variable to all queries coming from a certain domain.
For example, mydomain.com and proxydomain.com both show the same WordPress site, but for users visiting via proxydomain.com, I'd like to be able to handle their queries differently.
Additionally, I'd like to apply some different CSS styles for visitors coming through proxydomain.com.
I was thinking I could check for the query_var and apply classes based on the presence of that variable.
This is the code to add to your functions.php
file:
add_filter( 'body_class', 'domain_as_body_class' );
function domain_as_body_class( $classes ) {
$classes[] = sanitize_title( $_SERVER['SERVER_NAME'] );
return $classes;
}
It adds the sanitized domain of your site (i.e. mydomain-com
or proxydomain-com
) as class of the body
tag of your pages, so you can target the relative class for custom styles.
Update
For the queries you could add a function again in functions.php
like:
function is_proxydomain() {
return 'proxydomain.com' == $_SERVER['SERVER_NAME'];
}
And then use it when needed on a query:
if( is_proxydomain() ) {
$args = array(
// arguments for proxydomain.com
);
} else {
$args = array(
// arguments for mydomain.com
);
}
$query = new WP_Query( $args );