#Không cho Flatsome hiển thị html khi ẩn elements
Mặc định trong theme Flatsome, khi bạn ẩn đi các elements thiết kế riêng cho mobile, thì nó vẫn hiển thị html, css, script nếu có, làm cho tốc độ website bị giảm đi khá nhiều.
Đây là giải pháp xử lý DOM, CSS, JS dành cho bạn.
Đơn giản là bạn chỉ cần copy vào functions.php nhé
//Ngăn không tạo HTML trên Elements Flatsome
add_filter( ‘do_shortcode_tag’, ‘add_filter_shortcode_ux_visibility’, 10, 3 );
function add_filter_shortcode_ux_visibility( $output, $tag, $attr ) {
if( !isset($attr[‘visibility’]) )
return $output;if($attr[‘visibility’] == ‘hidden’)
return;if( ($attr[‘visibility’] == ‘hide-for-medium’) && wp_is_mobile() )
return;
elseif( ($attr[‘visibility’] == ‘show-for-small’) && !wp_is_mobile() )
return;
elseif( ($attr[‘visibility’] == ‘show-for-medium’) && !wp_is_mobile() )
return;
elseif( ($attr[‘visibility’] == ‘hide-for-small’) && wp_is_mobile() )
return;return $output;
}
Nếu bạn cảm thấy bài chia sẽ hữu ích cho bạn !
Hãy ủng hộ để mình có động lực viết thêm nhiều bài chia sẽ hay khác nữa.
