WordPress Search - GreenGeeks https://www.greengeeks.com/tutorials/category/wordpress-search/ How-to Website Tutorials Thu, 23 Feb 2023 17:27:42 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.2 How to Exclude Posts, Pages, Categories or Authors From WordPress Search https://www.greengeeks.com/tutorials/exclude-posts-pages-categories-authors-wordpress-search/ https://www.greengeeks.com/tutorials/exclude-posts-pages-categories-authors-wordpress-search/#comments Tue, 21 May 2019 14:34:18 +0000 https://www.greengeeks.com/tutorials/?post_type=ht_kb&p=25960 In this tutorial, I will show you how to use a plugin to exclude posts, pages, categories or authors from your WordPress search results. When …

How to Exclude Posts, Pages, Categories or Authors From WordPress Search Read More »

The post How to Exclude Posts, Pages, Categories or Authors From WordPress Search appeared first on GreenGeeks.

]]>
In this tutorial, I will show you how to use a plugin to exclude posts, pages, categories or authors from your WordPress search results.

When you search in WordPress, the results include all of the relevant posts and pages. However, you may have some situations where excluding a post or page, or even an author or category from search results is more ideal.

This article will show you how to do that easily with a WordPress plugin.

If you need to take customization even further, I will also point you to an article that shows you how to edit WordPress files to set search exclusions based on other criteria.

Exclude Posts and Pages From WordPress Search Results

The first step is to install the Search Exclude plugin.

Log in to your WordPress admin panel. In the left side of the WordPress admin panel, mouseover the “Plugins” link and click the “Add New” link.

how to exclude posts or pages from WordPress search step 1

Search for “Search Exclude,” click the “Install Now” button

how to exclude posts or pages from WordPress search step 2

Click the “Activate” button.

how to exclude posts or pages from WordPress search step 3

To Exclude a Post From WordPress Search Results

Go to your list of posts and Click the “Edit” link for the post you would like to exclude.

how to exclude posts or pages from WordPress search step 4

Scroll down to the bottom right of the post. Check the box for “Exclude from Search Results.”

how to exclude posts or pages from WordPress search step 5

Scroll up and click the “Update” button.

how to exclude posts or pages from WordPress search step 6

The post will now be excluded from the WordPress search results.

To Exclude a Page From WordPress Search Results

Excluding a page is done the same way you exclude a post. Go to your list of pages and click the “Edit” link for the post you would like to exclude.

Scroll down to the bottom right of the post. Check the box for “Exclude from Search Results.”

Click the “Update” button.

how to exclude posts or pages from WordPress search step 7

The page will now be excluded from the WordPress search results.

View or Edit the Pages and Posts Excluded From WordPress Search Results

Mouseover the “Settings” link and click the “Search Exclude” link.

how to exclude posts or pages from WordPress search step 8

The list will include posts and pages excluded from WordPress search results.

To stop excluding a post or page, uncheck the box for the post or page and click the “Save Changes” button.

how to exclude posts or pages from WordPress search step 9

That’s a pretty easy method to exclude posts and pages from WordPress search results. What if you want more advanced exclusions? For example, what if you need to exclude a specific category or author from search results? That’s a bit more complicated, but it’s possible with a few lines of code.

To Exclude a Category or Author From WordPress Search Results

There are a couple of different ways to exclude categories or authors from your search results. First, you can edit functions.php, one of the files in your WordPress theme. The other method is to create your own plugin to do the job. Creating a plugin sounds like a difficult task, but it’s pretty easy. Check out our tutorial, How to Create a Custom Site-Specific WordPress Plugin.

The benefit of making your own plugin is the code remains separate from the theme you’re using. So if you change themes, or update an existing theme, your code doesn’t get lost in the process. Of course, you can also protect your changes by creating a child theme, and making your functions.php changes in the child theme.

Whichever way you choose, you always want to avoid editing any theme files directly. If you do that, your changes will be overwritten when the theme is updated.

Excluding Specific Categories From WordPress Search Results

Before we get to the code, let’s look at how to identify a specific category.

Log in to your WordPress admin panel. Mouseover “Posts” and click the “Categories” link.

how to exclude posts or pages from WordPress search step 10

Mouseover the category you want to identify. The category ID is in the URL (in this example, the ID is 5).

how to exclude posts or pages from WordPress search step 11

Now you’re going to add the following code to functions.php. You can do this by using FTP programs like FileZilla by downloading, editing and uploading functions.php from your theme directory.

If you don’t want to use FTP, you can use the WordPress admin panel. Mouseover “Appearance” and click the “Theme Editor” link.

Whichever method you use, be sure to edit the functions.php file in your child theme, not in the main theme directory.

[ht_message mstyle=”info” title=”” show_icon=”” id=”” class=”” style=”” ]function wpb_search_filter( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( ‘cat’,’-5‘ );
return $query;
}
add_filter( ‘pre_get_posts’, ‘wpb_search_filter’ );[/ht_message]

In the code above you will replace “-5″ with the ID for your category. You can exclude multiple categories from the search results by separating the IDs with commas:

[ht_message mstyle=”info” title=”” show_icon=”” id=”” class=”” style=”” ]function wpb_search_filter( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( ‘cat’,’-5, -7, -10‘ );
return $query;
}
add_filter( ‘pre_get_posts’, ‘wpb_search_filter’ );[/ht_message]

Excluding Specific Authors From WordPress Search Results

Excluding authors is done in the same way we excluded categories. First, identify the author ID.

Mouseover “Users” and click the “All Users” link.

how to exclude posts or pages from WordPress search step 12

Mouseover the author you want to identify. The author ID is in the URL (in this example, the ID is 8).

how to exclude posts or pages from WordPress search step 13

Then add the following code to functions.php:

[ht_message mstyle=”info” title=”” show_icon=”” id=”” class=”” style=”” ]function wpb_search_filter( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( ‘author’,’-8‘ );
return $query;
}
add_filter( ‘pre_get_posts’, ‘wpb_search_filter’ );
[/ht_message]

In the code above you will replace “-8″ with the ID for the specific author you wish to exclude. You can exclude multiple authors from the search results by separating the IDs with commas:

[ht_message mstyle=”info” title=”” show_icon=”” id=”” class=”” style=”” ]function wpb_search_filter( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( ‘author’,’-8, -6, -4‘ );
return $query;
}
add_filter( ‘pre_get_posts’, ‘wpb_search_filter’ );
[/ht_message]

That’s All There Is to It

Now you know how to use a plugin to exclude posts or pages from your WordPress search results, as well as the code necessary to exclude categories or authors.

I hope you find these new tools helpful in customizing and fine-tuning your WordPress installation.

How many customizations do you use with WordPress? Do you prefer using plugins or adding code to theme files?

The post How to Exclude Posts, Pages, Categories or Authors From WordPress Search appeared first on GreenGeeks.

]]>
https://www.greengeeks.com/tutorials/exclude-posts-pages-categories-authors-wordpress-search/feed/ 2
How to Show Specific Post Types for Search Results in WordPress https://www.greengeeks.com/tutorials/show-specific-post-types-for-search-results-in-wordpress/ https://www.greengeeks.com/tutorials/show-specific-post-types-for-search-results-in-wordpress/#respond Mon, 29 Apr 2019 15:00:48 +0000 https://www.greengeeks.com/tutorials/?post_type=ht_kb&p=25272 Although WordPress has a basic method to let users search your site, it doesn’t always provide the best results. If you can fine-tune the tool, …

How to Show Specific Post Types for Search Results in WordPress Read More »

The post How to Show Specific Post Types for Search Results in WordPress appeared first on GreenGeeks.

]]>
Although WordPress has a basic method to let users search your site, it doesn’t always provide the best results. If you can fine-tune the tool, it could improve engagement and on-page time of the site. And showing specific post types in search is a good way to accomplish this.

After all, you want visitors to find exactly what they’re looking for if you want to keep them interested.

Today, I’ll show you how to add specific post types for search results in WordPress.

Why Showing Specific Post Types in Search Matters

By default, the search function of WordPress is not as intuitive as many may like. It doesn’t always provide the best results according to visitor criteria. Not to mention that you don’t have options for customizing the results.

When you expand what the search function can do, you deliver a more engaging layout for visitors.

For instance, it’s easy to build a WordPress custom search page where visitors can find more precise results. This has the potential to keep them browsing your content longer instead of looking elsewhere for answers.

Of course, you still need to create amazing content for those search functions to work properly.

Using Ivory Search

In this tutorial, I am going to demonstrate a bit of what Ivory Search can do in WordPress. It’s a solid plugin that comes with an easy-to-use interface. This plugin lets you customize results according to specific post types in search.

You can add it in the sidebar, on a post, page or even add a search in the menu bar.

You can limit authors, custom post types, metadata and even adjust for WooCommerce should you open an online store.

In a nutshell, it lets you build a WordPress custom search form while giving a lot of options for specific information.

Install and activate, “Ivory Search.”

Ivory Search

Upon activation, you’ll see a security and updates feature display. This is an optional setting, and you don’t have to allow the function.

Essentially, it’s the developer asking permission to send you update information regarding features and security.

Choose which option you prefer. For this tutorial, I’m simply clicking the “Skip” button. But this is completely up to you.

Choose Option

The next screen will show “Search Forms.” You can find this later by going to “Ivory Search” from the left panel in WordPress.

In this screen, you will see all of your available search forms. As you can create multiple search results for your site, here is where you would make adjustments.

Ivory search gives you a variety of ways to improve the searchability of your website. You can use widgets, create a specific search page or use a simple field in the navigation menu.

Adding New Search Results

Let’s build a new search form.

Click the “Add New” button on the top of the screen.

Add New Search

Give the search form a new name. This is for your reference only. Visitors will not see this display on the front end.

New Search Form Name

Select the options you want to enable for this search form. Here is where you can adjust specific post types in search results.

Specific Post Types Search Form

For example, you can enable “Attachment” under Post Types if you want visitors to search through images and files.

Enable Attachment Search

Something like this might benefit an online portfolio or a way to search image galleries.

Another method to fine-tune the WordPress search results page is to use the Category & Taxonomy Terms. In this section, you can select specific categories, tags and post formats. You can also include titles and descriptions.

Select Specific Category

This gives you a great way to let WordPress search within a category of your choice. Which means you can offer a custom search form in posts which only browse related content.

Unfortunately, a lot of Ivory Search’s more engaging options are locked behind the pro version. For example, you can limit search results according to author unless you upgrade.

Once you’re done making your adjustments, click the “Save Form” button.

Save Search Form

Excluding Search Results

What if you want to exclude specific post types in search?

Click the “Excludes” tab on the left of the search form.

Exclude Custom Search

This section works the same way as when you’re building your new search form. However, it will remove these options from the results page. Select the search criteria you want to avoid in the new search field.

Ignore Search Criteria

For example, we could choose to remove a tag by selecting it from the list.

Remove Tag From Search

Once you’ve selected your options, click the “Save From” button.

Save Search Excludes

Using Custom Search on a Post or Page

Now that we have a specific post types search ready, it’s time to add it to a page or post.

Click “Search Forms” under the Ivory Search tool on the left.

Search Forms

Copy the shortcode of the search form you want to use.

Search Form Shortcode

Paste the shortcode into any post or page you want to use the search field.

Paste Search Shortcode

If you’re using the Gutenberg Editor, you can use a shortcode block for this as well.

Once the post or page is published or updated, you’ll see the search field available.

Search Field Available

This lets you place the search field anywhere within your content.

Using a Custom WordPress Search Widget

What if you want a WordPress custom search form in a widget? Ivory Search can do that as well. This lets you put the search function in any sidebar of your theme.

Go to Appearance and click, “Widgets.”

WordPress Widgets

Drag and drop the “Ivory Search” widget into your sidebar.

Drop Search Widget

Choose which search from you want to use.

Choose Search Form

Click the “Save” button on the widget.

Save Search Widget

You will then have a search field in the sidebar in reference to the custom search query settings of the form you built.

Improve On-Page Time with Specific Post Types Search Results

Adding a WordPress custom search form improves your control over the results. It also gives you a chance to offer visitors a way to search specific post types. Offer your guests an easier way to browse your content. It may boost overall engagement of the site.

What search tools do you like to use in WordPress? Do you find visitors looking for certain information through your posts or pages?

The post How to Show Specific Post Types for Search Results in WordPress appeared first on GreenGeeks.

]]>
https://www.greengeeks.com/tutorials/show-specific-post-types-for-search-results-in-wordpress/feed/ 0
How to Add Search in the Menu Bar of WordPress https://www.greengeeks.com/tutorials/add-search-in-the-menu-bar-of-wordpress/ https://www.greengeeks.com/tutorials/add-search-in-the-menu-bar-of-wordpress/#respond Mon, 18 Mar 2019 15:00:35 +0000 https://www.greengeeks.com/tutorials/?post_type=ht_kb&p=24386 A search function can help visitors find exactly what they’re looking for on the website. This is especially useful if you have a lot of …

How to Add Search in the Menu Bar of WordPress Read More »

The post How to Add Search in the Menu Bar of WordPress appeared first on GreenGeeks.

]]>
A search function can help visitors find exactly what they’re looking for on the website. This is especially useful if you have a lot of content available. While the system has a default ability built-in, what if you want to add search to the menu bar of WordPress?

For example, what if your theme doesn’t use a sidebar? Perhaps you want to move the search field to streamline the site’s layout.

Something else to consider is how your site appears on mobile devices. As most themes shift the sidebar down, visitors using smartphones may not even see a search widget for the website.

Adding it to the top nav menu makes search easier to find for mobile users.

In this tutorial, I’ll show you how to add search to the menu bar in WordPress. This also helps if you want to create a custom nav menu on the website.

Using the Ivory Search Plugin

Today, I’m going to show you a bit of the Ivory Search plugin. It’s an easy tool to use and comes with a variety of options.

For instance, you can quickly create a WordPress search widget for the sidebar as well as add it to the navigation menu. It also supports WooCommerce for those who want to build an online store.

Install and activate the “Ivory Search” plugin.

Ivory Search

Upon activation, you’ll see an update notification appear. This is a security feature that is purely optional. You can choose to allow or skip the notifications.

Allow Notifications

For this tutorial, I’m going to click “Skip” to continue. Because the plugin is added to a temporary site, I really don’t need to worry too much about opting into this feature.

Once you choose the notification option, you’ll be taken to the Ivory Search form screen. By default, the plugin will create a basic form for you.

It is here where you can copy the shortcode of the search field and paste it into any post or page if you’d like.

For now, we’re using Ivory Search to add to a menu.

Click the link for “Settings” under the Ivory Search tool on the left admin screen of WordPress.

Ivory Search Settings

The plugin will find the menus you have active on your website. Click the switch to activate the menu search bar under “Select Menu.”

Activate Search

From here, you can also change some of the options for the search field such as form style, menu title, classes and activating the closing icon for search. These are optional depending on how you want the field to operate.

When you’re done with adjustments, click the “Save” button on the bottom.

Save Search Settings

You now have a search field in your menu bar.

Search Menu Nav Bar

NOTE: If you have a search widget for the Website, you might want to remove the feature. It may seem redundant to your visitors if there are two search fields close together on the site.

Two Search Fields

There’s nothing wrong with having multiple search bars available. But it’s probably more aesthetically pleasing to simply have the one.

Other Plugins to Try

While this tool is an easy way to add search to a menu in WordPress, the plugin isn’t the only one available. In fact, there are several that you might want to consider if you’re looking for different options.

Here are just a couple of the ones I found that might be of help.

Max Mega Menu

Max Mega Menu

Max Mega Menu has a lot of customizable options available especially if you buy the pro version of the plugin. While it’s more of an editing system for menus, it does come with the ability to add a search box.

It’s an exceptionally popular tool and has a lot of elements for creating custom menus in WordPress.

WP Mega Menu

WP Mega Menu

WP Mega Menu is another plugin that is more focused on customizing a nav bar. However, it also supports adding searching in the menu as well as a lot of other features.

This tool has several customizable features and supports mobile devices, Google Fonts, and various social icons. It’s a great way to add more to the nav menu aside from your search field.

Making Search Easier on Guests

Although a search widget for the website in the sidebar is helpful, adding it to your menu makes it easier for visitors regardless of the device they use. From aesthetics to functionality, consider the possibilities with a search nav menu item.

What kinds of pages, links or features do you use on your navigation menu? Do you find custom search options to be a valuable asset to your site?

The post How to Add Search in the Menu Bar of WordPress appeared first on GreenGeeks.

]]>
https://www.greengeeks.com/tutorials/add-search-in-the-menu-bar-of-wordpress/feed/ 0
How to Exclude Posts or Pages from WordPress Website Search https://www.greengeeks.com/tutorials/exclude-certain-pages-from-your-wordpress-website-search/ https://www.greengeeks.com/tutorials/exclude-certain-pages-from-your-wordpress-website-search/#comments Sun, 13 Jan 2019 16:00:50 +0000 https://www.greengeeks.com/tutorials/?post_type=ht_kb&p=23013 When you are searching WordPress, by default, the WordPress search displays all published posts and pages within the site that are relevant to your search. …

How to Exclude Posts or Pages from WordPress Website Search Read More »

The post How to Exclude Posts or Pages from WordPress Website Search appeared first on GreenGeeks.

]]>
When you are searching WordPress, by default, the WordPress search displays all published posts and pages within the site that are relevant to your search. However, when users are using the WordPress search function, more often than not, they are looking for a particular post and not a page on the site.

In this tutorial, I will demonstrate two straightforward ways to exclude posts or pages from WordPress search results. We will use the plugin technique, and we will also go over how to easily add some code into your functions.php file that will allow you to exclude WordPress posts or pages automatically when someone is performing a search on your website.

Why Exclude Posts or Pages From Search?

There are actually a number of reasons why you may want to exclude posts or pages from a WordPress website search.

Here are a couple of the main reasons:

  • You are publishing a private post or private page content for specific users, and you don’t want everyone to be able to find this content on your website.
  • The site includes paid content that shouldn’t be accessible to users who don’t have permission to view it.
  • You are trying to avoid irrelevant pages from showing up in search results on your site. A good example of this is the Homepage or Author Page showing up in results. Pages like those are usually not going to be relevant to a visitor’s search.

Basically, when you exclude posts and pages in WordPress search, you are allowing people to find relevant content faster and easier. It is not difficult to accomplish these changes.

Let’s take a look at how easily we can exclude posts or pages from a WordPress website search.

Exclude Posts or Pages from WordPress Search Using a Plugin

In order to exclude posts or pages form a WordPress website search using the plugin method, we are going to use the Search Exclude plugin.

Search exclude plugin

Search Exclude is a lightweight, simple-to-use plugin. It allows you to quickly and easily exclude any posts or pages from a blog search in WordPress.

The plugin has no settings to configure.

Essentially, it adds a new feature to the editing screen for posts and pages. You simply install and activate the plugin, and you can exclude pages by checking the checkbox that now appears within posts and pages.

Search Exclude also provides you with a “settings” page area that will list all the posts and pages you have excluded from the search. This way, you can easily find what you are looking for without going through all your posts or pages one-by-one.

Note: This plugin does support quick and bulk edit. It will also not affect your SEO in any way. Your sitemap will still include the pages or posts that you exclude from search.

Install and Activate Search Exclude

In order to use the Search Exclude plugin, it needs to be installed and activated. You can do this from the plugins page of your WordPress admin dashboard. Simply search for the plugin.

INstall and activate exclude posts and pages from wordpress website search plugin

Once you have located the plugin, click the “Install Now” button, then click the “Activate” button.

Once the plugin has been installed and activated, open any post or page in the editor. You will see that a new checkbox appears on the right side of the editor titled “Search Exclude.”

To exclude a post or page from a WordPress search results page, simply check the relevant box and then publish or update the content. Now the post or page will be excluded from the search results on your WordPress site.

Exclude posts or pages from wordpress search box

To see a list of all the posts and pages you have excluded over time, click on Settings > Search Exclude.

Click settings and then search exclude

Now you see a list of all the posts and pages you have excluded from your WordPress website search. This is an easy way to track and see everything you have done.

For example, maybe you see a sharp drop in traffic of a post that you wanted to remain within the site search. You can look in this list to ensure it wasn’t accidentally added.

List of posts and pages excluded from wordpress website search

Adding Code to Functions.php File to Exclude Posts or Pages

You can also remove posts or pages from your blog search in WordPress by adding some code to the functions.php file.

Note: If you edit your theme’s functions.php file, you run the risk that your changes will be overwritten when the theme updates. For that reason, it’s always best to use and edit a child theme whenever you plan to make changes to theme files.

To get to your website’s functions.php, file click on Appearance > Editor.

Click on appearance and then editor to access functions.php file

This will take you to the WordPress website files where you can edit your code. Click on “Theme Functions (functions.php),” and you will be ready to place the correct code to exclude WordPress pages.

Click on theme functions (functions.php) to edit code

Place the following code into your theme’s functions.php file:

//Alter the WordPress search to return ONLY posts, no pages
if (!is_admin()) {
  function search_filter_posts($query) {
    if ($query->is_search) {
  $query->set('post_type', 'post');
}
  return $query;
}
  add_filter('pre_get_posts','search_filter_posts');
}

What Does The Code Do?

Simply put, the code above checks to make sure that the WordPress search is not originating from any of the WordPress admin pages. Once it verifies that it isn’t, then the code forces searches for posts only by setting the post_type parameter and will exclude WordPress pages.

If you would like to do the opposite, force the WordPress search results page to show only pages, set the post_type parameter to “page.”

//Alter the WordPress search to return ONLY pages, no posts
if (!is_admin()) {
  function search_filter_pages($query) {
    if ($query->is_search) {
  $query->set('post_type', 'page');
}
  return $query;
}
  add_filter('pre_get_posts','search_filter_pages');
}

The Effects of Removing Something From Search Results

Private content or paid content isn’t generally part of your site statistics or analytics, so removing them from search won’t have a negative impact. On the other hand, removing a page or post from your onsite search results is likely to cause a drop in viewership.

That’s to be expected, but as I mentioned earlier, your sitemap should still contain the pages you exclude from search. So if your SEO game is strong, the effect of removing a page (or all pages) from search shouldn’t be overly negative.

Just remember that you are reducing the visibility of anything you exclude from search. So it’s a good idea to revisit your statistics or analytics a few weeks or months after making any exclusions.

Final Thoughts

Regardless of your reasons for wanting to remove something from search, the flexibility of WordPress makes it easy to do. Plugins are there for ease and speed, and template or file modifications for those who prefer to dig into the works.

That’s why we covered both methods in this tutorial. One method is not necessarily better than the other, it’s just a matter of your preference and experience level.

In addition to what we’ve talked about here, there is also a great option to tell your WordPress site to use more search engines when performing a search on the site. I hope this tutorial gave you a little insight into how easy it is to exclude posts or pages from WordPress website search.

Have you used the above plugin technique or code before? What is your preferred method of improving search functionality on your WordPress website?

The post How to Exclude Posts or Pages from WordPress Website Search appeared first on GreenGeeks.

]]>
https://www.greengeeks.com/tutorials/exclude-certain-pages-from-your-wordpress-website-search/feed/ 1
How to Add a Search Bar to WordPress Using Shortcode https://www.greengeeks.com/tutorials/add-search-bar-wordpress-shortcode/ https://www.greengeeks.com/tutorials/add-search-bar-wordpress-shortcode/#comments Wed, 16 May 2018 14:00:03 +0000 https://www.greengeeks.com/tutorials/?post_type=ht_kb&p=18660 Do you want to add a search bar on your WordPress website? Search bars are a great way to help your visitors find specific content …

How to Add a Search Bar to WordPress Using Shortcode Read More »

The post How to Add a Search Bar to WordPress Using Shortcode appeared first on GreenGeeks.

]]>
Do you want to add a search bar on your WordPress website? Search bars are a great way to help your visitors find specific content on your website. For example, if they are looking for a specific article, they can type the article name in to find it.  Not only are they useful, but they are also extremely easy to add.

Search bars become more useful to websites with time. The longer a website is around, the more content it will produce. The more content that is produced, the harder it is to find older content. Of course, this can be easily fixed by adding an archive page as well. Today, I will demonstrate how to add a search bar in WordPress by using a shortcode.

Why Add a Search Bar in WordPress

A search bar’s main purpose is pretty obvious, that is to allow visitors to search for more content. As a website gets older, content is pushed away from the front page and it becomes more difficult to find and thus be viewed. It’s generally only viewed by search engines and archive pages.

Of course, if your website does not rank high, you may not appear in search engine results. Relying on this as a method for older content to get views is not the best idea as an unranked website. Instead, giving visitors a way to easily search for content on the website is a much more reliable way to get views.

How to Add a Search Bar in WordPress with a Shortcode

Today, I will demonstrate how to add a search bar in WordPress by using a shortcode. No additional plugins will be necessary, but you will need access to your cPanel. Login for your cPanel is provided with your web hosting when you create an account. You should make a backup of your website before beginning. Whenever you are directly editing code, create a backup. This will allow you to revert to before you edited the code in case a fatal mistake was made.

Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.

Click on the File Manager option.

You need to locate your theme’s functions.php file. Click on the public_html directory, then click on the wp-content folder. Inside of this folder, you will find all of the content related to your website. Click on the themes folder and enter the folder of the theme you are currently using. Finally, right-click on the functions.php file and select the Edit option.

Select the "Edit" option.

A pop-up window will show up. This box will warn you to create a backup of your files before editing anything. This will ensure that you can revert your website back to when it was working if something goes wrong. Click on the “Edit” button. A new tab will open containing all of the code from the file.

Click on the "Edit" button.

Copy and paste the following lines of code into the functions.php file. This will create the shortcode for adding a search bar:[ht_message mstyle=”info” title=”” show_icon=”” id=”” class=”” style=”” ]function searchbar( $form ) {

$form = ‘






’;

return $form;
}

add_shortcode(‘searchbar’, ‘searchbar’);[/ht_message]

Once you have inserted the code into the functions.php file, click on the “Save Changes” button to finish.

Click on the "Save Changes" button.

Now it is time to place the search bar. You have quite a few options for placement. The first option is to directly insert the search bar into your posts or pages. Open an existing or a new post or page and paste [searchbar]. This will result in the following:

Search bar

Doing this has a few downsides. As you can see, the search bar will appear within a body of text. The second problem is you have to add this shortcode to every post and page you want it in. A better alternative is to add it to the sidebar. This will ensure it is visible on every page and post.

On the left-hand admin panel, click on Appearance and select the Widgets option. The widgets page allows you to customize sidebars, floating footer bars and other widgets on your website.

click on Appearance and select the Widgets option.

Locate a text widget and drag it onto your sidebar. Feel free to drag it elsewhere if you want it in a different location. Name your text widget and add the shortcode to the textbox. Click on the “Save” button when you are done.

Click on the "Save" button when you are done.

The search bar will now appear in your sidebar or wherever you placed the text widget.

Sidebar search bar

Congratulations, you have successfully added a search bar to your website. This is by far the best location for it and it will appear throughout your website instead of on pages or posts that have the shortcode on them. Other locations work as well. As long as you can insert the shortcode, it will appear.

Keep Your Content Easy to Find

As you add more content, it becomes increasingly difficult to get all of your content to be viewed. The older content will really struggle as time goes on. Adding features like search bars or archive pages will help you improve your website’s accessibility. Keep in mind that you may wish to create a redirect page in case your visitor’s search does not pull anything up.

Currently, the search bar will give a 404 error if the search is not found. Adding a redirect will help keep your visitors away from these error messages. I would recommend redirecting them to the archive page so they can see all of the content your website offers.

How do you like the search bar? Where have you placed the search bar on your website?

The post How to Add a Search Bar to WordPress Using Shortcode appeared first on GreenGeeks.

]]>
https://www.greengeeks.com/tutorials/add-search-bar-wordpress-shortcode/feed/ 3
How to Use the Best WordPress Search Engines on Your Site https://www.greengeeks.com/tutorials/how-to-use-the-best-wordpress-search-engines-on-your-site/ https://www.greengeeks.com/tutorials/how-to-use-the-best-wordpress-search-engines-on-your-site/#comments Wed, 05 Apr 2017 14:00:04 +0000 https://www.greengeeks.com/kb/?p=10232 Google and Bing are not the only ways people can search for relevant content. Many will use the search bar on your website to find …

How to Use the Best WordPress Search Engines on Your Site Read More »

The post How to Use the Best WordPress Search Engines on Your Site appeared first on GreenGeeks.

]]>
Google and Bing are not the only ways people can search for relevant content. Many will use the search bar on your website to find materials. However, not all searches pull up good results or an attractive appearance. This has potential to hinder the performance of your site from the human perspective.

Luckily, there is a way you can add the best WordPress search methods. This can also be done without programming knowledge or creating your own extensive algorithms. With a few selections in settings, the search bar can turn into one of the most important areas of your website.

In this tutorial, I’m going to show you how to use the best search engine alternatives for your WordPress website. After all, giving visitors an easier way to find what they’re looking for only serves to benefit you in the long run.

Why revamp the search method on the site?

While the default searching ability of WordPress is useful, it lacks some of the capabilities many people have come to enjoy. For one, the autocomplete feature can be quite handy when trying to find content before hitting the enter button.

Another thing to consider is that some search methods are severely lacking when it comes to finding specifics. For example, some plugins that will look amazing pale in comparison to when someone uses the “site:” command in Google. I’ll explain this capability later.

It’s all about giving people what they are looking for as quickly as possible. If someone has to spend too much time trying to refine their search because it’s not matching with results, they’ll lose interest in the site rather quickly. While it may not be the worst design addition to a website, it still has potential to be a hindrance.

Giving the search bar a more elegant and efficient display can also boost visitor retention. People enjoy interaction and having more of an “experience” when visiting a site than just merely viewing text on a screen. This is why many developers are putting in more interactive elements into designs and content.

Using the SearchIQ Plugin

The Search function in WordPress gives visitors a useful tool. However, you can take it a step further and receive detailed metrics about how they use it. searchIQ has that capability. Although this plugin does offer a free version, the “pro” upgrade expands what you can do.

Other features of searchIQ include cross-domain searching, autocomplete fields, real-time analytic data and a sleek thumbnail display to show the content of your site in results. This plugin requires the use of an account in searchIQ’s website, but the starter account is free.

To use searchIQ:

Go to the website for searchIQ and create a free account.

search iq website

Go to the plugins area of WordPress, click “Add New” and search for searchIQ.

find search iq

Install and activate the plugin. This will add a new function to the left admin panel in WordPress called, “searchIQ.”

activate search iq

Click into this link. Here is where you enter the API key from your searchIQ account.

api key

Once the API key is inserted, click the submit button to save the settings.

api submit

The next step from this plugin is to synchronize your posts. This gives you an option of what kind of content you want to add to the database for searching. For example, posts, pages, custom CSS files, feedback, FAQ plugins and more can all be added with a click of the corresponding check box. Once you make the selections for what to include, click the “Synchronize Posts” button.

synchronize posts

A progress bar will appear and show you when searchIQ has finished indexing your site.

progress bar

Click the options tab. From here, you can make a variety of changes depending on how you want the search bar to behave. Autocomplete, setting up a static page in WordPress for results and the search algorithm can all be adjusted. Click “Save” when you’re ready to continue.

option tab

Click the tab for the Results Page. In this section, you have a great deal of customizing control that lets you alter labels, colors, number of results and more. You’re even provided with a preview window to show what your changes will look like on the site. Click the button to submit your changes when you’re done.

result page

Click the Autocomplete tab. Here, you can alter how the autocomplete feature appears when someone searches for a topic. Click the button to submit changes if you’ve made any.

autocomplete tab

Click the Mobile tab. The searchIQ plugin is optimized for mobile users. Here, you can make changes to how the plugin behaves for smartphones and tablets. Unfortunately, this section doesn’t have a preview window like the others.

mobile tab

Go to the widgets area in WordPress located under, “Appearance.”

widgets

Locate the “searchIQ search box” widget and drag it over to your sidebar.

drag search iq to sidebar

From here, you can change the default text that shows in the box before users begin typing. Otherwise, simply click save.

click save

Now, your website will use the abilities and features of searchIQ. You will have to access the plugin’s website directly if you wish to view statistics regarding how your new tool is working for visitors.

Other Plugins to Add Engagement to Searching

Alogolia

alogolia

Algolia is another third-party engine requiring an account to activate it. Like the one I featured above, this plugin also has a free account. It can handle up to 10,000 records and allows for 100,000 requests from website users. It is similar to searchIQ in almost every way but fewer customization options.

WPSolr

wpsolr

WPSolr is a bit more convoluted when it comes to controls. However, this also means there is great possibility for customization. While the free version does offer some great capabilities for search, the premium services include integrations with various eCommerce plugins and other tools for WordPress.

Search & Filter

search and filter

The Search & Filter plugin is more of an extension to the WordPress system already in place. I mention it in this tutorial because it expands what can be done through the basic function. You can add custom fields, templates and uses a drag-and-drop editing system. One of its endearing features is the ability to work with WooCommerce and WP eCommerce for those setting up an online store.

Ok, so what is the “site:” command in Google?

When searching for content, a lot of people simply put in the keyword and cross their fingers. What if you want to find content and a specific website? This is when you would use the “site:” ability. It looks like this:

site:greengeeks.com WordPress

This command will search GreenGeeks.com for every instance of WordPress using its famous algorithm for discovering quality content. When you install some of the best WordPress search plugins, compare the results to using the above command on your site. Of course, you want to replace the domain and keyword with your own.

Alternatively, you can incorporate a Google custom search in WordPress to have the most popular engine in the world work for you.

More than a search feature…

You don’t have to be limited to the default search abilities of WordPress to accentuate the site. There are many ways you can add the best WordPress search ability without being a programmer. Give your visitors the interactive experience they crave and make your content easier to find. It may just convince someone to add your site to their bookmarks.

What kind of additions have you added to WordPress to engage your users? Is your site easy to use when it comes to looking for specific content?

The post How to Use the Best WordPress Search Engines on Your Site appeared first on GreenGeeks.

]]>
https://www.greengeeks.com/tutorials/how-to-use-the-best-wordpress-search-engines-on-your-site/feed/ 2