Jump to content

Remove text from Search results on the Search page

Recommended Posts

I would like to remove the file name text that is displayed on the Search Results page.

When I search for the word "broccoli" the returned results show the .png image file name as well. I do not want these image files to be shown in the search results, I would like only the text of the page, and/or any description of the page, such as the SEO description if one exists, to be displayed here.

Screenshot 2023-03-01 073313.png

Link to comment
  • Replies 1
  • Views 143
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Add to Settings > Advanced > Code Injection > Footer

<!-- Remove jpg in search page -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
const attrObserver = new MutationObserver((mutations) => {
  mutations.forEach((mu) => {
    if (mu.type !== "attributes" && mu.attributeName !== "class") return;
    trimEXT();
  });
});

const ELS_test = document.querySelectorAll(".search-results");
ELS_test.forEach((el) => attrObserver.observe(el, { attributes: true }));

function trimEXT() {
  $(".search-results img").ready(function () {
    $(".sqs-search-page .sqs-title").html(function () {
      return $(this).html().replace(".jpg", "").replace(".png", "").replace(".jpeg", "");
    });
  });
}

$(document).ready(function () {
  trimEXT();
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.