Below, you’ll find a detailed guide on how to add the Media Search Enhanced 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 Media Search Enhanced Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Media Search Enhanced Plugin and the shortcodes it provides:
"Media Search Enhanced is a WordPress plugin designed to optimize and refine your media library search. It allows precise filtering, ensuring you find the perfect media file swiftly."
- [mse-search-form]
Media Search Enhanced [mse-search-form] Shortcode
The ‘mse-search-form’ shortcode from the Media Search Enhanced plugin is designed to customize the search form. This shortcode replaces the default search form with a media-specific search form. It adds an input field for ‘post_type’ with a value of ‘attachment’, enabling users to search specifically in media files. The placeholder text can be customized, and additional CSS classes can be added to the form. The final form is returned through the ‘mse_search_form’ filter for further customization.
Shortcode: [mse-search-form]
Examples and Usage
Basic example – A simple usage of the ‘mse-search-form’ shortcode without any additional parameters. This will display a search form with the default placeholder text “Search Media…”.
[mse-search-form /]
Advanced examples
Modifying the placeholder text of the search form by using the ‘mse_search_form_placeholder’ filter. This example changes the placeholder text to “Search Images…”.
function change_mse_placeholder( $text ) {
return __( 'Search Images...', 'domain' );
}
add_filter( 'mse_search_form_placeholder', 'change_mse_placeholder' );
Adding a custom class to the search form by using the ‘mse_search_form_class’ filter. This example adds a class ‘custom-search’ to the form.
function add_custom_class( $class ) {
return $class . ' custom-search';
}
add_filter( 'mse_search_form_class', 'add_custom_class' );
Modifying the search form output by using the ‘mse_search_form’ filter. This example adds a custom button to the form.
function modify_mse_form( $form ) {
return str_replace( '', '', $form );
}
add_filter( 'mse_search_form', 'modify_mse_form' );
PHP Function Code
In case you have difficulties debugging what causing issues with [mse-search-form]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'mse-search-form', array( $this, 'search_form' ) );
Shortcode PHP function:
function search_form( $form = '' ) {
$domain = $this->plugin_slug;
$s = get_query_var( 's' );
$placeholder = ( empty ( $s ) ) ? apply_filters( 'mse_search_form_placeholder', __( 'Search Media...', $domain ) ) : $s;
if ( empty( $form ) )
$form = get_search_form( false );
$form = preg_replace( "/(form.*class=\")(.\S*)\"/", '$1$2 ' . apply_filters( 'mse_search_form_class', 'mse-search-form' ) . '"', $form );
$form = preg_replace( "/placeholder=\"(.\S)*\"/", 'placeholder="' . $placeholder . '"', $form );
$form = str_replace( '</form>', '<input type="hidden" name="post_type" value="attachment" /></form>', $form );
$result = apply_filters( 'mse_search_form', $form );
return $result;
}
Code file location:
media-search-enhanced/media-search-enhanced/public/class-media-search-enhanced.php
Conclusion
Now that you’ve learned how to embed the Media Search Enhanced 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.
Leave a Reply