-
-
Save Lonsdale201/2086f902d6e842f74450918996f67d99 to your computer and use it in GitHub Desktop.
JetEngine - Dynamic visibility - Is Front Page
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
// place the code in the child theme functions.php or a custom code snippets plugin. | |
// Best usage in the Listing Grid | |
// Open an widget, dynamic visibility, and search the Is Front page visibility under the Custom category. | |
add_action( 'jet-engine/modules/dynamic-visibility/conditions/register', function( $conditions_manager ) { | |
class Is_Front_Page_Condition extends \Jet_Engine\Modules\Dynamic_Visibility\Conditions\Base { | |
public function get_id() { | |
return 'is-front-page'; | |
} | |
public function get_name() { | |
return __( 'Is Front Page', 'jet-engine' ); | |
} | |
public function get_group() { | |
return 'custom'; | |
} | |
public function check( $args = array() ) { | |
$front_page_id = get_option( 'page_on_front' ); | |
$current_page_id = get_the_ID(); | |
$is_front_page = ( $front_page_id == $current_page_id ); | |
$type = isset( $args['type'] ) ? $args['type'] : 'show'; | |
return ( 'hide' === $type ) ? !$is_front_page : $is_front_page; | |
} | |
public function is_for_fields() { | |
return false; | |
} | |
public function need_value_detect() { | |
return false; | |
} | |
} | |
$conditions_manager->register_condition( new Is_Front_Page_Condition() ); | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment