Apply function.php filter only if url not has /amp/

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/

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x