1. PROMO Upgrade to Pro Membership @ $99 / Lifetime & access all our 16+ premium Divi extensions: Divi Block, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Solved PHP error when using site search

Discussion in 'Free Divi Community Forum' started by Kabbott, Mar 2, 2020.

  1. Kabbott

    Kabbott New Member

    I have been getting an error whenever a search is done on my WordPress/Divi website. The results are listed, but there is an error listed first:

    WARNING: USE OF UNDEFINED CONSTANT THEMENAME - ASSUMED 'THEMENAME' (THIS WILL THROW AN ERROR IN A FUTURE VERSION OF PHP) IN /path-to-the-theme/SEARCH.PHP ON LINE 17

    Line 16-18 of the search.php file are as follows:

    <header class="page-header">
    <span class="search-page-title">
    <?php printf( esc_html__( 'Search Results for: %s', themename ), '<span>' . get_search_query() . '</span>' ); ?></span>
    </header><!-- .page-header -->

    WordPress ver: 5.3.2
    PHP ver: 7.3
    Divi ver: 4.3.4 with a child theme

    How do I fix this?
     
    1. PRO MEMBER PERKS Divi Cart Count Plugin - Easily add cart count to your Divi cart icon. 6 different styles to choose from:Learn More
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    Perhaps it's like this:

    <?php printf( esc_html__( 'Search Results for: %s', $themename ), '<span>' . get_search_query() . '</span>' ); ?></span>
     
  3. Kabbott

    Kabbott New Member

    I had in my old code:

    esc_html__( 'Search Results for: %s', themename )

    The themename portion either should be a string literal 'themename' or more likely replaced with the folder name of your theme (themeslug). For example, when you installed the Twenty Twenty theme it's theme folder is twentytwenty and it's textdomain is 'twentytwenty'. A similar example in Twenty Twenty would look like this:

    esc_html__( 'Search Results for: %s', 'twentytwenty' )

    adding the quotes around the themename worked!
     
    1. PRO MEMBER PERKS Divi Block Pro - 30+ premade custom header designs for you to choose from:View Demo