[Flatsome] Ngăn cho các Block trong UXBuider tạo HTML khi chọn hidden

Tính năng: Ngăn các Block trong UX tạo html khi chọn hidden, mặc định Flatsome chỉ dùng css display none để ẩn những html đó.

Lợi ích: Làm được 2 template riêng cho mobile và desktop, kèm theo cũng rất nhiều lợi ích khi không phải doshorte code không dùng đến.

// Add custom Theme Functions here
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;
}

Chúc các bạn sử dụng đoạn code trên hiệu quả nhé! Có thắc mắc hoặc lỗi chỗ nào cũng vui lòng comment cho mình biết nữa

Nguồn : VietCoders

Đánh giá post

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Hotline: 0974.0707.83(Zalo/Viber)