Give provides several useful conditional functions to allow developers to more easily extend or customize their websites with Give.

NOTE: These functions are only available in Give Core version 1.6+

is_give_form()

Returns true if the visitor is currently viewing a single Give form page. Note that this functions will not return true within a Give widget or shortcode is used in other posts/pages.

Return

(bool) True when viewing single give form, false otherwise.

Example usage

Adds a unique Body class to all single Give form pages

Add body class only on single Give form pages

function myprefix_single_give_body_class( $classes ) {
    if( is_give_form() ) {
    	return array_merge( $classes, array( 'class-name' ) );
    }
}

add_filter(‘body_class’, 'myprefix_single_give_body_class');

is_give_category()

Returns true if the visitor is currently viewing a Give category page. When left blank it will apply to any category page. The term can also be defined in the function.

Parameter

$term (string) The category term slug. Default is blank.

Return

(bool) True when viewing give form category archive, false otherwise.

Example usage

Enqueues a script only on the Give category page with the term “youth”.

Enqueue a script only on a Give Category called "Youth"

function myprefix_enqueue_give_category_script() {
    if ( is_give_category( 'youth') ) {
    	wp_enqueue_script( 'my-js', 'filename.js', false );
    }
}

add_action( 'wp_enqueue_scripts', 'myprefix_enqueue_give_category_script' );

is_give_tag()

Returns true if the visitor is currently viewing a Give tag page. When left blank it will apply to any tag page. The term can also be defined in the function.

Parameter

$term (string) The tag term slug. Default is blank.

Return

(bool) True when viewing give form tag archive, false otherwise.

Example usage

Enqueues a script only on the Give tag page with the term “annual”.

Enqueue a script only if on the Give Tag Archive called "Annual"

function myprefix_enqueue_give_tag_script() {
    if ( is_give_tag( 'annual') ) {
    	wp_enqueue_script( 'my-js', 'filename.js', false );
    }
}

add_action( 'wp_enqueue_scripts', 'myprefix_enqueue_give_tag_script');

is_give_taxonomy()

Returns true if the visitor is currently viewing a page which is any Give taxonomy. This could be a category, or a tag, or even if you’ve created your own additional taxonomy for Give.

Return

(bool) True when viewing give form taxonomy archive, false otherwise.

Example usage

Enqueues a script for any Give taxonomy page.

Enqueue a script on all Give taxonomy pages

function myprefix_enqueue_give_taxonomy_script() {
    if ( is_give_taxonomy() ) {
    	wp_enqueue_script( 'my-js', 'filename.js', false );
    }
}

add_action( 'wp_enqueue_scripts', 'myprefix_enqueue_give_taxonomy_script');