• Recent
  • Tags
  • Popular
  • Register
  • Login
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 801 Views
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.
  • E
    EpsilonAdmin
    last edited by EpsilonAdmin 11 Jul 2020, 21:53 7 Nov 2020, 17:57

    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
    1 out of 1
    • First post
      1/1
      Last post

    Suggested Topics

    • E

      [Solved] EduMall theme does not show Smart Excerpts and broken the search results page

      Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions
      1 11 Jul 2022, 21:24
      11 Jul 2022, 21:24
      0 Votes
      1 Posts
      508 Views
      No one has replied
    • E

      [Solved] The Astra theme does not show Smart Excerpt for files

      Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions
      1 25 Aug 2021, 07:58
      25 Aug 2021, 07:58
      0 Votes
      1 Posts
      907 Views
      No one has replied
    • E

      [Solved] Polylang limits search by language taxonomy

      Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions fix patch polylang search taxonomy
      1 22 Feb 2021, 23:11
      22 Feb 2021, 23:11
      0 Votes
      1 Posts
      765 Views
      No one has replied
    • E

      I don't see excerpt in Thrive Nouveau theme

      Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions thrive nouveau theme excerpt
      1 6 Nov 2020, 22:26
      6 Nov 2020, 22:26
      0 Votes
      1 Posts
      714 Views
      No one has replied
    • E

      [Solved] WP Knowledgebase publications (kbe_knowledgebase) do not show in search results

      Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions knowledgebase kbe
      1 9 Jun 2020, 23:08
      9 Jun 2020, 23:08
      0 Votes
      1 Posts
      679 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