• Resolved abbottwp

    (@abbottwp)


    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?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    You have in your 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' )

    The textdomain helps translations of your theme. You can see it as the 2nd parameter in any __*() functions -> esc_html__(). If this is a custom theme or you do not expect translations you could ignore this parameter entirely:

    esc_html__( 'Search Results for: %s' )

    Currently, since it’s not encapsulated by quotes PHP thinks it’s a pre-defined constant that it should be looking for but cannot find ( since themename is not a defined constant ).

    Thread Starter abbottwp

    (@abbottwp)

    Yup, adding the quotes around the theme name worked. THANK YOU!!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP errors when using search’ is closed to new replies.