Skip to content

Configuring superwords

Esa-Matti Suuronen edited this page Jun 4, 2021 · 11 revisions

Pages can have any number of superwords, but this is not what superwords is meant to be used for. Adding many superwords on a page worsens the end used experience.

Superwords are ment for lifting handful of content pages with different superwords. If all pages have superwords, no page is special.

Pages can expose superwords by two different ways:

  • Using wp-valu-search plugin filters
  • Using scraper defaults

wp-valu-search filter is placed in php-code, and require action from your service provider each time superwords are changed.

Default selectors scrape contents from HTML DOM elements with specific attributes. These can be potentially used by the content management personel.

wp-valu-search superword filter

documentation

Filters can be placed anywhere in php-code, but in this example we place them in wp-content/themes/<theme-name>/lib/valu-search.php

If you follow this example, be sure to include the file in wp-content/themes/<theme-name>/functions.php

  1. Create wp-content/themes/<theme-name>/lib/valu-search.php
  2. Copy example code from below into valu-search.php
<?php

namespace ValuSearch;

function example_superwords_rewrite( $superwords, $post ){
	// modify superwords based on post
	if(get_permalink($post) !== "<url you want to target here>"){
		return $superwords;
	}

    $superwords = [
        'your-secondary-superword-here',
        'your-superword-here',
    ];

	return $superwords;
}
add_filter( 'valu_search_superwords', __NAMESPACE__ . '\\example_superwords_rewrite', 10, 2 );
  1. Change url you want to target in example code

  2. Change superwords you want to expose

  3. Validate filter functionality by navigating to <url you want to target here>/?_vsid _vsid is a query parameter send by Valu Searchcrawler, and wp-valu-search plugin exposes data on page in a script tag.

    In browser developer tools, search for valu-search on the page. You should find a script tag like this:

    <script type="application/json" id="valu-search">
        {"showInSearch": ...,
        ...
        "superwords":["your-superword-here", "your-secondary-superword-here"],
        ...
    </script>
  4. Done! After next crawl the page will have the superwords you specified and should be the first search result with any superwords you specified

scraper default superword selectors

Scraper looks for elements with data-vs-superwords data-attribute and their contents.

    <div data-vs-superwords>superword</div>
    <span data-vs-superwords>more<span>

results in: ["superword","more"]

Multiple words in single element are separated into their own superwords

    <div data-vs-superwords>superword1 superword2 superword3</div>

results in: ["superword1", "superword2", "superword3"]

Element that holds the custom fields does not need to be visually visible. It can be hidden with style="display:none;" or in some other way.

Element holding the superwords can be located anywhere on the webpage.

Clone this wiki locally