Ajax Search Pro Knowledge Base
Buy Ajax Search Pro!DocumentationGet SupportDevelopment
  • Knowledge Base
  • Safe Coding Guideline
  • Hooks
    • Filters
      • Query & Output
        • asp_query_args
        • asp_query_{type}
        • asp_cached_content
        • asp_pre_get_front_filters
        • asp_before_ajax_output
        • asp_shortcode_output
        • asp_print_search_query
      • Keyword Suggestions
      • Search Results
        • asp_suggested_phrases
        • asp_results
        • asp_cpt_results
        • asp_buddyp_results
        • asp_attachment_results
        • asp_comment_results
        • asp_blog_results
        • asp_terms_results
        • asp_peepso_group_results
        • asp_peepso_activities_results
        • asp_only_keyword_results
        • asp_only_non_keyword_results
        • asp_result_groups
      • CSS & JS
        • asp_load_js
        • asp_load_css
        • asp_load_css_js
      • Template & Output
        • asp_icl_t
      • Index Table Related
        • asp_index_on_save_stop
        • asp_indexing_keywords
        • asp_indexing_string_pre_process
        • asp_indexing_string_post_process
        • asp_post_content_before_tokenize_clear
        • asp_post_content_before_tokenize
        • asp_post_excerpt_before_tokenize
        • asp_post_title_before_tokenize
        • asp_file_contents_before_tokenize
        • asp_post_permalink_before_tokenize
        • asp_index_terms
        • asp_post_custom_field_before_tokenize
        • asp_index_cf_contents_before_tokenize
        • asp_index_before_shortcode_execution
        • asp_index_after_shortcode_execution
    • Templating
      • Filter layouts Templating
      • Result Templating
    • Constants
  • Frontend Filters
    • Taxonomy Filters
      • Restricting results to the same category as the current post object
      • How to automatically check/select filter values based on the archive page?
    • Frontend filters API
  • Tips & Miscellaneous
    • Divi
      • Divi Blogs Live Search and Filter
    • Jet Engine
      • Jet Engine Listing Grid Live Search and Filter
      • Searching Jet Engine Custom Meta Storage fields
    • Tutorials
      • PDF results thumbnails
      • Demo setup: Staff search and Filter
      • Demo Setup: WooCommerce Search
      • Demo setup: WooCommerce Shop Search and Filter
      • Demo Setup: Events Search – Events Manager
      • Demo Setup: Events Search – The Events Calendar
      • Compact ‘pop-out’ search bar placement on specific pages only
      • Index Table – Indexing ACF repeater field titles and contents
      • Change Suggested Phrases conditionally
      • How to add shortcode to the results content?
      • How to add variables to the “redirect to url” or the “show more url”?
      • Indexing Shortcodes within custom field contents
    • Post Types
      • Index Table - Indexing child post contents to parent
      • Limit results to specific post IDs only
      • Filter posts (or CPT) which user can’t access
      • Restricting results by user Groups using the Groups plugin by itthinx
      • Limiting results to specific posts by parent ID
      • Limit results to current page children
      • Excluding posts or CPT by parent ID(s)
      • Searching posts, pages (or any CPT) by specified keywords only, nothing else
      • Showing the post type name in result title or content
      • Searching within given categories/taxonomy terms only
      • Search only in the same category as the current post or page (single page)
      • Search only within the current category (or any taxonomy) archive
      • Filtering pages by page template
    • Taxonomy Terms
      • Displaying taxonomy name in taxonomy term results
      • Limiting taxonomy term results to specific term IDs only
    • WooCommerce
      • Displaying On Sale products only in WooCommerce
      • Ordering product by stock status
      • Making a product in-stock & out of stock filter
      • Add to cart button for Vertical and Horizontal results
      • Get formatted price in result title or in content
      • Showing products in-stock only
      • Showing in-stock and backorder products only
      • Excluding hidden catalog products
      • Showing featured products first
      • How to search products & product SKU?
      • How to search Products by variation SKUs?
      • Search product attributes
      • How to search users by city, state, zip code… ?
    • Compatibility
      • WPML Compatibility issues and fixes
    • Files & Media
      • Searching Image EXIF metadata
    • Other
      • Restrict results from the current author archive page
      • Presetting search options via a custom URL
      • Matomo analytics tracking integration
      • Replace search keywords (whole words)
      • Replace or remove characters from search phrase
      • Adding spaces in search phrase between alphabetics and numbers
      • How to change the results URL to something else?
      • Numbering the results
      • How to use the search without the live ajax feature, as a regular search?
      • Empty search input field on the search results page
      • Singular and Plural keywords index
  • Other
    • SearchQuery
    • REST API
    • Building a custom REST API
    • Javascript API
    • Javascript Hooks
      • asp_redirect_url
      • asp_search_data
      • asp_live_load_html
      • asp_search_html
      • asp_compact_width
    • Theme Functions
Powered by GitBook
On this page
  • Quick configuration
  • Positioning with a custom code – allowing exclusions/inclusions
  1. Tips & Miscellaneous
  2. Tutorials

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 4 years ago

This quick tutorial will help you configure and place a pop-out search bar to the sidebar of your site using a custom code – allowing inclusion or exclusion from specific pages.

For generic use please check the (includes a video tutorial).

Quick configuration

Make sure to enable the compact box layout mode under the Layout Options -> Compact box layout panel. For this tutorial I recommend the following configuration:

  • Compact layout final width: 320px

  • Compact search box position: fixed (or absolute may also work)

Positioning with a custom code – allowing exclusions/inclusions

Add this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!

Adjustable variables within the code (lines 7-17):

  • $id -> the search instance ID

  • $exclude_on_pages -> list of page IDs, where the search should not be visible. Leave it empty, if not in use.

  • $include_on_pages -> list of page IDs, where the search should be visible. Leave it empty, if not in use.

  • $exclude_on_archives -> true or false. If true, then then the search will not be visible on post type archives.

  • $exclude_on_tax_archives -> list of taxonomies. The search will not be visible on listed taxonomy archive pages.

  • $exclude_on_front -> true or false. If true, the search will not be visible on the front page.

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.']');
	}
}

What is this, and where do I put this custom code?
Compact Box Layout documentation