Title: Prevent search from including javascript
Last modified: March 24, 2022

---

# Prevent search from including javascript

 *  Resolved [bizangodan](https://wordpress.org/support/users/bizangodan/)
 * (@bizangodan)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/prevent-search-from-including-javascript/)
 * First off, thanks for making a great plugin! I love the updated excerpt functions
   that actually show relevant text from the content.
 * Only issue I found is that searching for certain words that may come up in scripts
   will sometimes be included in the new excerpts in the search results.
 * For instance if I try to search “document” It will start showing “$(document).
   ready(function(){…}” in the search excerpt for some pages.
 * The site uses acf pro and has many custom acf blocks which have scripts. I just
   wanted to check if there was a quick fix I could do before separating out all
   the scripts and enqueue-ing them instead
 * Is there anyway to exclude all text within “<script></script>” tags from the 
   queries?
 * I’m using a custom theme by the way and have full access to the files.
    -  This topic was modified 4 years, 2 months ago by [bizangodan](https://wordpress.org/support/users/bizangodan/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Epsiloncool](https://wordpress.org/support/users/epsiloncool/)
 * (@epsiloncool)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/prevent-search-from-including-javascript/#post-15493246)
 * Hi [@bizangodan](https://wordpress.org/support/users/bizangodan/)
 * As I understood you, the acf blocks you included to pages have some javascript/
   css code that you want to exclude from the search index and from the excerpts,
   right?
 * The “Strip HTML Tags From Post Contents” flag in the settings allows to remove
   tag names, but it still make tag content indexed (including <script> and <style
   > tags).
 * So what should we make?
 * We can post-process the post content just before the indexing. It will also do
   the trick for excerpts. Let’s use the code like this:
 *     ```
       add_filter('wpfts_index_post', function($index, $post)
       {
       	global $wpfts_core;
   
       	// This code will work properly only with "Strip Tags Option DISABLED"
       	if ($post && $wpfts_core) {
       		$t = $index['post_content'];
       		if (in_array($post->post_type, array('post', 'page'))) {	// You can add more post_types here
       			// Remove <script> with content
       			$t = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $t);
       			// Remove <style> with content
       			$t = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', "", $t);
       		}
   
       		// This code will actually strip tags (instead of disabled option)
       		$t = $wpfts_core->contentStripTags($t);
       		$index['post_content'] = html_entity_decode(str_replace('&nbsp;', ' ', $t));
       	}
   
       	return $index;
       }, 20, 2);`
       ```
   
 * This should definitely help.
 *  Plugin Author [Epsiloncool](https://wordpress.org/support/users/epsiloncool/)
 * (@epsiloncool)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/prevent-search-from-including-javascript/#post-15493254)
 * Sorry, forgot to notice [@bizangodan](https://wordpress.org/support/users/bizangodan/)
 * you should uncheck “Strip HTML Tags From Post Contents” option (make it OFF) 
   to make this code working properly.
 *  Thread Starter [bizangodan](https://wordpress.org/support/users/bizangodan/)
 * (@bizangodan)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/prevent-search-from-including-javascript/#post-15493284)
 * [@epsiloncool](https://wordpress.org/support/users/epsiloncool/)
    Thanks so much
   for the quick response
 * That seemed to work!
 * Thanks again, I appreciate your time on this

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Prevent search from including javascript’ is closed to new replies.

 * ![](https://ps.w.org/fulltext-search/assets/icon-256x256.png?rev=3084761)
 * [WP Fast Total Search - The Power of Indexed Search](https://wordpress.org/plugins/fulltext-search/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/fulltext-search/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/fulltext-search/)
 * [Active Topics](https://wordpress.org/support/plugin/fulltext-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fulltext-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fulltext-search/reviews/)

## Tags

 * [excerpt](https://wordpress.org/support/topic-tag/excerpt/)
 * [script](https://wordpress.org/support/topic-tag/script/)
 * [search results](https://wordpress.org/support/topic-tag/search-results/)

 * 3 replies
 * 2 participants
 * Last reply from: [bizangodan](https://wordpress.org/support/users/bizangodan/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/prevent-search-from-including-javascript/#post-15493284)
 * Status: resolved