WPFTS Pro Main Site WPFTS Community Forum
    • Recent
    • Tags
    • Popular
    • Register
    • Login
    Get WPFTS Pro today with 25% discount!

    [Solved] No excerpts shown in search results in Storefront theme

    Scheduled Pinned Locked Moved Recipes and Known Solutions
    storefrontthemeexcerptfix
    1 Posts 1 Posters 1.2k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • EpsilonAdminE Offline
      EpsilonAdmin
      last edited by EpsilonAdmin

      Another good and clean theme (and it's also free) called Storefront which not show excerpts in search results neither for posts and pages nor for files. This way, search for files by their content works well, but the Storefront theme only displays titles (filenames).

      Usual and the simplest way to fix this is to redefine the search.php template in the child theme like we did it for the Thrive Nouveau theme. But may we achieve that without creating the child theme? If you downloaded the theme from the official WP repository, it has not child theme in the package.

      After the fast analyze of the theme, I found that the excerpt is generated by the function storefront_post_content located in the file inc/storefront-template-functions.php and it uses the the_content() call to show both full-content and short content of posts. You may check WP documentation to understand how it works.

      But this method is not acceptable for us, because WPFTS Pro catches and uses the the_excerpt() hook to show its famous Smart Excerpt. So what I gonna do is to replace this function completely.

      I don't need to remove the existing function from the theme, because the theme only creates this function if it was not defined before. So what I need to do is to DEFINE my function before the theme.

      I going to create a simple plugin and put this code into it.

      /**
       * This code will be called BEFORE the Storefront's original code
       */
      if (!function_exists('storefront_post_content')) {
      
          function storefront_post_content()
          {
              global $wp_query;
      
              ?>
              <div class="entry-content">
                  <?php
                      /**
                       * Functions hooked in to storefront_post_content_before action.
                       *
                       * @hooked storefront_post_thumbnail - 10
                       */
                      do_action( 'storefront_post_content_before' );
      
                      if ($wp_query && $wp_query->is_main_query() && $wp_query->is_search) {
                          // We are using the_excerpt() for search result always!
                          the_excerpt();
                      } else {
                          // We are using old method for all other pages
                          the_content(
                              sprintf(
                                  __( 'Continue reading %s', 'storefront' ),
                                      '<span class="screen-reader-text">' . get_the_title() . '</span>'
                                  )
                              );
                      }
      
                      do_action( 'storefront_post_content_after' );
      
                      wp_link_pages(
                          array(
                              'before' => '<div class="page-links">' . __( 'Pages:', 'storefront' ),
                              'after'  => '</div>',
                          )
                      );
                      ?>
                      </div><!-- .entry-content -->
                      <?php	
               }
      }
      

      Note: this code should be run from the plugin to get a priority before the original code.

      To shorten your work, I have compiled this code into a small plugin and you can download it here.
      wpfts-addon-storefront-1.0.0.zip

      Was this helpful for you?

      https://e-wm.org

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post

      Suggested Topics

      • EpsilonAdminE

        [Solved] Exclude some PDF from results when using Download Monitor

        Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions
        1
        0 Votes
        1 Posts
        997 Views
        No one has replied
      • EpsilonAdminE

        I don't see excerpt in Thrive Nouveau theme

        Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions thrive nouveau theme excerpt
        1
        0 Votes
        1 Posts
        1k Views
        No one has replied
      • EpsilonAdminE

        [Solved] Does not show Smart Excerpt with Total Theme

        Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions smart excerpt total theme theme
        1
        0 Votes
        1 Posts
        837 Views
        No one has replied
      • EpsilonAdminE

        [Solved] The plugin shows wrong results for search with BeTheme template

        Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions betheme theme
        1
        0 Votes
        1 Posts
        1k Views
        No one has replied
      • EpsilonAdminE

        [Solved] Incompatibility with Flatbase theme

        Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions flatbase excerpt theme
        1
        0 Votes
        1 Posts
        974 Views
        No one has replied

      Additional Resources

      • My Account
      • Buy WPFTS Pro
      • Community Forum
      • Affiliate Program
      • Privacy Policy
      • Terms & Conditions
      • Contact Us
      • Coupon Partner

      Be the first to read the news!

      We are always improving our products, adding new functions and fixes. Subscribe now to be the first to get the updates and stay informed about our sales! We are not spammy. Seriously.

      Join Us Now!

      We are a professional IT-team. Many of us have been working in a Web IT field for more than 10 years. Our advanced experience of software development has been employed in the creation of the WordPress FullText Search plugin. All solutions implemented into the plugin have been used for 5 or more years in over 60 different web-projects.

      We are looking forward to your comments, requests and suggestions in relation to the current plugin and future updates.

      ewm-logo-450

      The forum powered by NodeBB | Contributors