gutenberg html tags search

Gutenberg posts are being searched by HTML tags or comments

There is a well-known problem that WordPress publications that are created using Gutenberg can be found in a search by completely unusual words. This problem appeared after the introduction of Gutenberg in WordPress. In order to create block pages, Gutenberg uses special meta tags inside post_content, which are marked as comments. However, since MySQL cannot automatically recognize HTML tags and comments in the text, it considers them as part of useful text and therefore uses them for searching.

This problem seems to have no quick fix. Users differently out of the situation. Some decide to prohibit the search for words that may be Gutenberg tags. Others guess to create a meta-field in a post, copy there the cleaned-up content of the post (post_content) and make a search by this meta field instead.

The WFTS plugin allows you to solve this problem quite elegantly, even without a single line of code.

It’s all about the magic hook wpfts_index_post, which allows you to process the text before placing it in the search index. Now, all we have to do to get rid of the tags is to paste this code somewhere in the file function.php the following code:

add_filter('wpfts_index_post', function($index, $post)
{
    $index['post_content'] = strip_tags($index['post_content']);
    return $index;
}, 3, 2);

Starting from version 2.27 (and free version 1.16), this code is no longer required to be added, since it is already included in the body of the plug-in and is activated by the “Strip Tags From Content” option, which, by the way, is enabled by default.

Strip Tags from Post Content

Strip Tags from Post Content

0 0 голоса
Рейтинг статьи
Was it useful? Share the experience!
Подписаться
Уведомить о
guest
0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии