WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] searchform in front page returns fatal error (3 posts)

  1. deko
    Member
    Posted 4 years ago #

    I put the following searchform in my front page:

    <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
    <input type="text" name="s" id="s" size="25" />&nbsp;
    <input type="submit" value="<?php esc_attr_e('Search Postpositive'); ?>" /></form>

    It works fine when the page is accessed from the index.php in www root (i.e. http://www.myblog.examle.com/index.php).

    But if someone goes to

    http://www.myblog.example.com/wp-content/themes/mytheme/index.php

    I get a fatal error:

    Call to undefined function: bloginfo()

    I realize this is expected behavior, but is there a way to test for something (some variable?) when the /wp-content/themes/mytheme/index.php is called directly?

    If so, I assume I could just omit the searchform (there are no other wp function calls on the page).

  2. esmi
    Forum Moderator
    Posted 4 years ago #

  3. deko
    Member
    Posted 4 years ago #

    no one would - unless they're looking for some security vulnerability.

    Here's the fix:

    <?php if (@constant('WP_USE_THEMES')) : ?>
    <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
    <input type="text" name="s" id="s" size="25" />&nbsp;&nbsp;
    <input type="submit" value="<?php esc_attr_e('Search'); ?>" />
    </form>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic