Strip HTML Tags From Search Results
I don’t know about the code you are trying to use, personally I would never use a solution that excludes results, it’s very possible the item being searched for is in those results and excluding them is only a degradation of service.
Instead you can use the search.php
template file to adjust how your search results are displayed, there is a very handy function available in php called strip_tags()
which will remove all HTML tags from a string.
UPDATE:
Specifically:
search.php
:
<?php
/**
* Template Name: Search Results Page
*/
get_header();
?>
<section id="primary">
<div id="content" role="main">
<?php if (have_posts()): ?>
<header class="page-header"><?php _e("Search Results"); ?></header>
<div class="entry-content">
<?php
while (have_posts()): the_post();
echo strip_tags(get_the_content());
endwhile;
?>
</div>
<?php endif; ?>
</div>
</section>
<?php
get_footer();