Question

I applied a filter to remove theme styles and javascript in function.php, but I want this to happen only if the url not ends with /amp/

Was it helpful?

Solution

What is amp? Is it tag or category or page? You should use standard wordpress functions like is_page() is_category() is_tag().

You can also use $wp->request. It will return the request URI. If the address is "http://example.com/slug1/slug2" it will return slug1/slug2 then use explode() function to split it.

<?php  $uri =  $wp->request; 
$slugs = explode("/",$uri);//variable $slugs will have array of slugs 

//$slugs[count($slugs)-1] will return last slug
if($slugs[count($slugs)-1] != "amp") {
//Apply your filter filter here
}
 ?>

Remember $wp is a global variable so if you want to use it inside a function the must use the keyword global before it.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top