Skip to content

Configuring superwords

JoonasVaris edited this page Jun 4, 2021 · 11 revisions

Superwords are ment for lifting handful of content pages with different superwords. For example lifting page http://www.site.test/summer-vacation when using search terms "vacation", "holiday" as the most important search result.

Pages can expose superwords by two different ways:

  • Using wp-valu-search plugin filters
  • Using data-attributes recognized by the scraper

wp-valu-search filter is placed in php-code.

Valu Search crawler scrapes contents from HTML DOM elements with specific attributes. For superwords this attribute is data-vs-superwords

Note: If all pages have superwords, no page is special. Pages can have any number of superwords, but this is not what superwords is meant to be used for. Careless superword usage can worsen the end user user-experience.

wp-valu-search superword filter

documentation

  1. Add valu_search_superwords wp-filter
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', 'example_superwords_rewrite', 10, 2 );
  1. Change url you want to target in example code

  2. 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>
  3. Done! After next crawl the page will have the superwords you specified and should be the first search result with any superwords you specified

Superword data-attributes

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 separated with spaces 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