Compact ‘pop-out’ search bar placement on specific pages only
PreviousDemo Setup: Events Search – The Events CalendarNextIndex Table – Indexing ACF repeater field titles and contents
Last updated
Last updated
add_action('wp_footer', 'asp_insert_sc_to_footer', 99999);
function asp_insert_sc_to_footer() {
// Replace this with the search ID you want to use
$id = 1;
// Comma separated list of Pages (or any CPT) where the search should be excluded. Leave it empty to ignore.
$exclude_on_pages = '1, 2, 3';
// Comma separated list of Pages (or any CPT) where the search should be excluded. Leave it empty to ignore.
$include_on_pages = '';
// Exclude on archive pages?
$exclude_on_archives = false;
// Exclude on category (or any taxonomy) archive pages. Comma separated list of taxonomies.
$exclude_on_tax_archives = 'category, tag';
// Should it be visible on the front page? true or false
$exclude_on_front = false;
// -------- DO NOT TOUCH BELOW ----------
if ( is_front_page() && $exclude_on_front )
return false;
if ( is_archive() && $exclude_on_archives )
return false;
$eta = array_filter( explode(",", str_replace(' ', '', $exclude_on_tax_archives)), 'strlen' );
foreach ( $eta as $_eta ) {
if ( ($_eta == 'tag' || $_eta == 'post_tag') && is_tag() )
return false;
if ( $_eta == 'category' && is_category() )
return false;
if ( is_tax($_eta) )
return false;
}
$epa = array_filter( explode(",", str_replace(' ', '', $exclude_on_pages)), 'strlen' );
$ipa = array_filter( explode(",", str_replace(' ', '', $include_on_pages)), 'strlen' );
$pid = get_the_ID();
if ( !is_wp_error($pid) ) {
if ( in_array($pid, $ipa) || !in_array($pid, $epa) ) {
echo do_shortcode('[wd_asp id='.$id.']');
}
} else {
echo do_shortcode('[wd_asp id='.$id.']');
}
}