Search for keywords, like "PayPal", "Recurring Donations", and more.

Conditional Functions

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

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

is_give_form()

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

Return

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

Example usage

Adds a unique Body class to all single GiveWP form pages

Add body class only on single GiveWP 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 GiveWP 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 GiveWP form category archive, false otherwise.

Example usage

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

Enqueue a script only on a GiveWP 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 GiveWP 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 GiveWP form tag archive, false otherwise.

Example usage

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

Enqueue a script only if on the GiveWP 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 GiveWP taxonomy. This could be a category, or a tag, or even if you’ve created your own additional taxonomy for GiveWP.

Return

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

Example usage

Enqueues a script for any GiveWP taxonomy page.

Enqueue a script on all GiveWP 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');
Last updated 5 years ago

Start Fundraising Better Today!

Get GiveWP Today
GiveWP Plans