WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Confused about file names: searchform, Search Form and search_form

[Resolved] Confused about file names: searchform, Search Form and search_form

  • I’m a bit confused about the various names that php template files seem to have.

    For example,

    1) my search form’s file name is “searchform.php”, but in the Appearance > Editor > Template list it also has a name of “Search Form”.
    2) And when you want to include it into somewhere such as the sidebar, you call it “search_form”, as in <?php get_search_form(); ?>

    Where do these alternative names come from?

    I’ve created a new newsletter subscription form called “subscribeform.php”. I’d also like to give it a plain English name and include it in my sidebar.php. How do I do this?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • 1) my search form’s file name is “searchform.php”, but in the Appearance > Editor > Template list it also has a name of “Search Form”.

    “searchform.php” is the name of the php file as it is viewed by the file system on your server. “Search Form” is a title that the Template Editor gives to the aforementioned file. Basically, “Search Form” is a human readable version of the filename.

    2) And when you want to include it into somewhere such as the sidebar, you call it “search_form”, as in <?php get_search_form(); ?>

    get_search_form() is what is known a a Template Tag which is basically a php function that allows you display different parts of your blog in various different templates. This Template Tag looks for a file called searchform.php in your current theme’s directory and if it finds it, it will include this file in the template. If the file is not found , it will print a default version of a search form to the screen.

    Where do these alternative names come from?

    I think they are just there to confuse new users:)

    I’ve created a new newsletter subscription form called “subscribeform.php”. I’d also like to give it a plain English name and include it in my sidebar.php. How do I do this?

    Not sure about giving it a Plain English name, but it is rather easy to include into your sidebar. First, upload subscribeform.php to your server – into your current theme’s directory. Next, open your sidebar.php file in a text editor and add the following code in the spot where you would like the form to appear:

    include( TEMPLATEPATH . '/subscribeform.php' );

    If your theme is widget enabled, you will want to put this bit of code outside of the “widget conditional”… it looks something like this:

    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    Best of luck to ya!

    Thanks mfields

    So just curious, but can you explain why the template tag calls <?php get_search_form(); ?> with the hyphen when the file itself is searchform.php without a hyphen?

    Absolutely no idea… it’s just a name after all 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Confused about file names: searchform, Search Form and search_form’ is closed to new replies.
Skip to toolbar