PHPackages                             sitecrafting/gearlab-tools-wordpress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. sitecrafting/gearlab-tools-wordpress

ActiveWordpress-plugin[API Development](/categories/api)

sitecrafting/gearlab-tools-wordpress
====================================

Integrate your WordPress site with the GearLab Tools platform

v1.1.0(5y ago)0563↓50%[3 PRs](https://github.com/sitecrafting/gearlab-tools-wordpress/pulls)MITPHP

Since Dec 17Pushed 1y ago2 watchersCompare

[ Source](https://github.com/sitecrafting/gearlab-tools-wordpress)[ Packagist](https://packagist.org/packages/sitecrafting/gearlab-tools-wordpress)[ RSS](/packages/sitecrafting-gearlab-tools-wordpress/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (22)Used By (0)

GearLab Tools for WordPress
===========================

[](#gearlab-tools-for-wordpress)

[![Travis CI build status](https://camo.githubusercontent.com/1f415733113d886ff5a8cf0c13c2fb1570e34dfa0db51984c1d68b833a42db51/68747470733a2f2f6170692e7472617669732d63692e6f72672f736974656372616674696e672f676561726c61622d746f6f6c732d776f726470726573732e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/1f415733113d886ff5a8cf0c13c2fb1570e34dfa0db51984c1d68b833a42db51/68747470733a2f2f6170692e7472617669732d63692e6f72672f736974656372616674696e672f676561726c61622d746f6f6c732d776f726470726573732e7376673f6272616e63683d6d6173746572)

Integrate your WordPress site seamlessly with the GearLab Tools suite.

Installation
------------

[](#installation)

### Installing Manually

[](#installing-manually)

Download the .zip archive of the latest release and place the extracted directory in `wp-content/plugins`. Activate the plugin from the WP Admin as you normally would.

### Installing via Composer

[](#installing-via-composer)

Add the requirement to your composer.json:

```
composer require sitecrafting/gearlab-tools-wordpress --prefer-dist
```

*NOTE:* if you are tracking your WordPress codebase as one big monorepo, the `--prefer-dist` flag is important! It tells Composer to find and download the .zip archive instead of the full Git repository. Without this flag, it will create the plugin directory as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) and strange things will happen.

Usage
-----

[](#usage)

### Getting Started

[](#getting-started)

After installing and activating the plugin, go to the *GearLab Tools* section of the WP Admin. Enter your *API Key*, *Collection ID*, and *Base URI* as provided by GearLab. All settings are required.

### Search

[](#search)

With GearLab Tools, you can override the default WordPress search functionality, which is extremely limited by default, with results from the ElasticSearch crawler that powers GearLab Search. To do this you must first enter your settings as described above, in **Getting Started**.

Once you've entered your GearLab Tools settings, but before enabling overriding WordPress search globally, you can test from the command line to see if you get results. To do this, run `wp gearlab search `. You should see a JSON object like this:

```
{"results": [{"url": "https://www.example.com/example-page", "title": "Example Page", "snippet": "Some content"}, ...]}
```

Once you've entered the settings above correctly, you're ready to enable GearLab Tools Search to override the default WP search. Enable the option **Override default WordPress search** and save the settings again. You should now see a basic search results page rendered by GearLab Tools whenever you perform a search.

#### Search Shortcode

[](#search-shortcode)

Out of the box, you can use the `[gearlab_search]` shortcode in any RTE that supports shortcodes. This is the recommended approach for most cases.

However, basic searches (using WordPress's standard `s` query param), will still render your theme's default search.php template (assuming there is one). You can redirect global searches to the page your shortcode lives on in the Settings. Go to **Settings &gt; GearLab Tools** and select **Redirect searches to a specific page**. Type the URI, e.g. `/search`, in the text box that appears.

Save your changes and you're good to go! Default searches will now redirect to your page. Note that all query string parameters will be preserved *except* `s`, which will be renamed to `glt_search` to avoid conflicting with WordPress's default functionality.

#### Overriding Timber templates

[](#overriding-timber-templates)

This plugin has special support for [Timber](https://www.upstatement.com/timber/).

To override how Timber renders your search results, you can add Theme Overrides. These are files that the plugin looks for in your theme and loads it if finds them, falling back to the plugin's own templates if it does not. These files are (relative to your theme root):

- `gearlab-tools/search.php`: Main PHP template to run. If you want to support e.g. a UI for filtering on `metaTag`, override this file and see the examples below.
- `(Timber template path)/gearlab-tools/search.twig`: Main Twig template for rendering the search page. If you don't need to change the backend functionality (e.g. how search filters are applied) and only want to change how the overall search results page is rendered, override this file.
- `(Timber template path)/gearlab-tools/search-result.twig`: Render a single search result with Twig.

...where `(Timber template path)` is anywhere that Timber already knows to look for Twig templates. The most commone place is the `templates` or `views` directory in your theme.

#### Override the GearLab search.php template

[](#override-the-gearlab-searchphp-template)

Place something like the following in your theme at `gearlab-tools/search.php` (this example does not rely on Timber):

```
// NOTE: the client may throw an exception!
use Swagger\Client\ApiException;

// Call out to the API
try {
  // search with some sensible defaults
  $response = GearLab\search();
} catch (ApiException $e) {
  error_log($e->getMessage());
  $response = [];
}

wp_header();

// Render results
foreach (($response['results'] ?? []) as $result) : ?>
