Collapse-Pro-Matic Expand_On Attribute

[expand title="Trigger Text" expand_on="is_search"]Target Text[/expand]

Trigger Text

This new conditional expand feature is based on a request by user thisimnot. We introduce a new attribute called expand_on that accepts a comma separated list of WordPress Conditional Tags that will auto-expand the element if true.

For example. The following element should be displayed as collapsed when viewing the front (blog) page, but when viewing the single post or the search results page it will be shown as expanded.

[expand title="Trigger Text" expand_on="is_single, is_search"]Target Text[/expand]

Trigger Text

Adding Custom Conditional

To create a custom conditional that checks for a custom query_var, for example, is_hilite:

Step 1: Place the following in your child theme’s function.php file:

//Add query vars
add_filter( 'query_vars', 'my_query_vars' );
function my_query_vars( $qvars ) {
    $qvars[] = 'hilite';
    return $qvars;
}

//Add custom hilite conditional
function is_hilite(){
	if(get_query_var( 'hilite')){
		return true;
	}
	return false;
}

The shortcode:

[expand title="Trigger Text" expand_on="is_hilite"]Target Text[/expand]

Example:

Trigger Text

test

Here, at the very bottom of this page is a little collapse element to test the internal WordPress Search.

grapple