• Resolved Jack

    (@jack1132132)


    Hello,

    It seems from the settings I can exclude a whole page or a whole folder, but not a folder within a page.

    I’ve tried the following:

    function option_ewww_image_optimizer_exclude_paths_func($exclude_paths){
    	
    	if(is_page(50))
    		$exclude_paths.= '/wp-content/uploads/ultimatemember/';
    	
    	return $exclude_paths;
    }
    
    add_filter( 'option_ewww_image_optimizer_webp_rewrite_exclude', 'option_ewww_image_optimizer_exclude_paths_func' , 9999 ,1);

    However, the current page isn’t set when the function is called so it doesn’t work.

    Is there any workaround to this?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support adamewww

    (@adamewww)

    Hi Jack1132132,

    I double-checked with Shane on this and he suspects that this is coming into play with what you are trying to do: https://developer.wordpress.org/reference/functions/is_page/
    Specifically – “Due to certain global variables being overwritten during The Loop, is_page() will not work. In order to call it after The Loop, you must call wp_reset_query() first.”

    As EWWW’s WebP function filters the HTML after the entire page has been built, this would be too late. If you can’t get is_page() to work with wp_reset_query(), you may have to resort to checking against the request URI. You can use add_query_arg( null, null ) to get that info.

    Thread Starter Jack

    (@jack1132132)

    using add_query_arg(null, null) works!

    code:

    function option_ewww_image_optimizer_exclude_paths_func($exclude_paths){
    	
    	$page = sanitize_url(add_query_arg( null, null ));
    	
    	if(substr($page, 0, 5) == '/user'){
    		$exclude_paths.= '/wp-content/uploads/ultimatemember/';
    	}
    
    	return $exclude_paths;
    }
    add_filter( 'option_ewww_image_optimizer_webp_rewrite_exclude', 'option_ewww_image_optimizer_exclude_paths_func' , 9999 ,1);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excluding image folder inside specific page’ is closed to new replies.