Last active
January 13, 2025 15:24
-
-
Save Crocoblock/65387eeb54340f91c8df5be199a9a83d to your computer and use it in GitHub Desktop.
JetEngine Change wrapper tags to <ul> <li> in Listing Grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class JEC_Change_Tags { | |
public function __construct() { | |
add_filter( 'jet-engine/listing/render/jet-listing-grid/settings', array( $this, 'apply_settings' ) ); | |
add_filter( 'jet-engine/listing/grid/nav-widget-settings', array( $this, 'nav_settings' ), 10, 2 ); | |
add_filter( 'jet-engine/listing/render/default-settings', array( $this, 'default_settings' ) ); | |
} | |
//set 'is-ul-listing' setting to 1 if tags need to be changed to ul / li | |
//change tags | |
public function apply_settings( $settings ) { | |
$settings['is-ul-listing'] = $this->is_ul_listing( $settings ); | |
if ( ! empty( $settings['is-ul-listing'] ) ) { | |
$settings['list_items_wrapper_tag'] = 'ul'; | |
$settings['list_item_tag'] = 'li'; | |
} | |
return $settings; | |
} | |
//set default value for compatibility with JetSmartFilters | |
public function default_settings( $settings ) { | |
$settings['is-ul-listing'] = ''; | |
return $settings; | |
} | |
//save 'is-ul-listing' to nav settings for compatibility with Load More | |
public function nav_settings( $widget_settings, $settings ) { | |
$widget_settings['is-ul-listing'] = $this->is_ul_listing( $settings ); | |
return $widget_settings; | |
} | |
//check if 'is-ul-listing' setting should be set for block / widget / element | |
// | |
//for Elementor and Block Editor - widget / block must have 'listing-ul' class | |
//for Bricks Builder - element must have a 'data-listing-ul' attribute | |
public function is_ul_listing( $settings ) { | |
if ( ! empty( $settings['is-ul-listing'] ) ) { | |
return 1; | |
} | |
$class = ''; | |
if ( ! empty( $settings['_css_classes'] ) ) { | |
$class = $settings['_css_classes']; | |
} elseif ( ! empty( $settings['className'] ) ) { | |
$class = $settings['className']; | |
} elseif( ! empty( $settings['_attributes'] ) && is_array( $settings['_attributes'] ) ) { | |
foreach ( $settings['_attributes'] as $attr ) { | |
if ( ! empty( $attr['name'] ) && $attr['name'] === 'data-listing-ul' ) { | |
$class = 'listing-ul'; | |
break; | |
} | |
} | |
} | |
return false !== strpos( $class, 'listing-ul' ) ? 1 : ''; | |
} | |
} | |
//create an instance of a class | |
new JEC_Change_Tags(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in Elementor and Block Editor - add class
listing-ul
to the listing that should have tags changed,in Bricks Builder - add
data-listing-ul
attribute with any value