0

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/

1 Answer 1

0

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.

1
  • Thanks for helping, i will use this code inside function.php, my code in function.php function disable_scripts_styles() { wp_dequeue_style('publisher'); wp_dequeue_style('better-framework-main-fonts'); } add_action('wp_enqueue_scripts', 'disable_scripts_styles', 100); and the url is sitename.com/article/amp so i dont apply this function if the url has amp Feb 8, 2021 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.