# Compact ‘pop-out’ search bar placement on specific pages only

&#x20;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 [Compact Box Layout documentation](https://wpdreams.gitbooks.io/ajax-search-pro-documentation/content/layout_settings/compat_search_box_layout.html) (includes a video tutorial).

![](https://wp-dreams.com/wp-content/uploads/2018/01/02/admin/16114/admin/compact-featured-min.jpg)

## 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)

![](https://wp-dreams.com/wp-content/uploads/2018/01/02/admin/16114/admin/compact-configuration-min.jpg)

## 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.

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/tutorials/compact-pop-out-search-bar-placement-on-specific-pages-only.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
