Ivory Search – WordPress Search Shortcode

Below, you’ll find a detailed guide on how to add the Ivory Search – WordPress Search Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Ivory Search – WordPress Search Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Ivory Search – WordPress Search Plugin and the shortcodes it provides:

Plugin Icon
Ivory Search – WordPress Search Plugin

"Ivory Search – WordPress Search Plugin is a robust tool that enhances your website's search functionality. It effortlessly integrates search options into your menu for improved user navigation."

★★★★☆ (1263) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 5.2.4
Included Shortcodes:
  • [ivory-search]

Ivory Search [ivory-search] Shortcode

The ‘ivory-search’ shortcode from the Add-Search-To-Menu plugin generates a search form. It first checks if the search is disabled or if it’s a feed. Then, it validates the ‘id’ attribute, returning an error message if it’s invalid. If valid, it retrieves the corresponding search form, generates its HTML, and returns it. .

Shortcode: [ivory-search]

Parameters

Here is a list of all possible ivory-search shortcode parameters and attributes:

  • id – Specifies the unique identifier for each search form.
  • title – Sets the title of the search form.

Examples and Usage

Basic example – Displays the default search form when no specific ID is provided.

[ivory-search /]

Advanced examples

Displays a specific search form by referencing the ID. The shortcode will only display the search form if the ID is valid and the form exists.

[ivory-search id=3 /]

Using the shortcode to display a specific search form by referencing both ID and title. The form will first try to load by ID, but if not found, it will try to load by title.

[ivory-search id=3 title="Search Form" /]

If the ID is not provided or invalid, and the title is not found, the shortcode will return an error message.

[ivory-search id=0 title="Nonexistent Form" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ivory-search] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ivory-search', array( $is_admin_public, 'search_form_shortcode' ) );

Shortcode PHP function:

function search_form_shortcode( $args ) {

		if ( is_feed() ) {
			return '[ivory-search]';
		}

		$is_settings = get_option( 'is_settings', array() );
		if ( isset( $is_settings['disable'] ) ) {
			return;
		}

		$atts = shortcode_atts(
			array(
				'id'	=> 0,
				'title'	=> '',
			),
			$args, 'ivory-search'
		);

		$atts = array_map( 'sanitize_text_field', $atts );
		$display_id = '';
		if ( ! isset( $atts['id'] ) || empty( $atts['id'] ) ) {
			$page = get_page_by_path( 'default-search-form', OBJECT, 'is_search_form' );

			if ( ! empty( $page ) ) {
				$atts['id'] = $page->ID;
				$display_id = 'n';
			}
		} else if ( ! is_numeric( $atts['id'] ) || 0 == $atts['id'] ) {
			return '[ivory-search 404 "Invalid search form ID '. esc_html( $atts['id'] ) .'"]';
		}

		$search_form = IS_Search_Form::get_instance( $atts['id'] );

		if ( ! $search_form ) {
			return '[ivory-search 404 "The search form '. esc_html( $atts['id'] ) .' does not exist"]';
		} else if ( 'default-search-form' == $search_form->name() && isset( $is_settings['default_search'] ) ) {
			$display_id = 'n';
		}

		$form  = $search_form->form_html( $atts, $display_id );

		return $form;
	}

Code file location:

add-search-to-menu/add-search-to-menu/includes/class-is-admin-public.php

Conclusion

Now that you’ve learned how to embed the Ivory Search – WordPress Search Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *