WordPress.org

Support

Support » How-To and Troubleshooting » search widget on my non-wordpress home page?

search widget on my non-wordpress home page?

  • I have a custom site that has a wordpress blog (in a sub-directory). Is it possible to have the search box (widget) appear on my custom home page? I was hoping for a snippet of code to insert on my home page.
    thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • wpismypuppet

    @wordpressismypuppet

    If you want to use WordPress outside of WordPress you simply need to require() wp-load.php, which is found in the root of the WordPress installation. Since your site is in a sub-directory, you’ll want to look in that folder. Then you’ll call the search form where ever you want it. So something like this:

    <?php
        require( 'subfolder/wp-load.php' );
        get_search_form();
    ?>

    Things to pay attention to…

    1) The path inside the require() function will change according to where you are relative to where the wp-admin.php file is. Also, replace “subfolder” with your actual folder name :).

    2) The require() function need only be called ONCE per page it’s used on. In fact, I use require_once() as it does the same thing, but does a check to make sure the file hasn’t already been called. Just a safety measure on my part.

    3) Though the require() function CAN go anywhere, it’s generally good practice to place it a the very top of the file. This means you would separate the get_search_form() function from the require() function, as you’ll want the search form somewhere appropriate on the page

    Let me know if this makes sense. Good luck.

    I have this in the beginning of my <body>
    <?php
    require( ‘wordpress/wp-load.php’ );
    ?>

    and this where I want the search widget to appear
    <?php get_search_form(); ?>

    but it is not executing the code. ‘wordpress’ is my wordpress/blog directory, where the wp-admin directory is and the wp-load.php file is. Not sure if I am missing something. Thank you for your response!

    wpismypuppet

    @wordpressismypuppet

    Ah… you might need the absolute path instead of a relative one. Try this instead:

    <?php require( $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php' ); ?>

    still no luck. The site is http://www.knowthyselfwellness.com. The search widget should appear under the mailing list form. when I view source I see the code but not the data it should have pulled in.

    wpismypuppet

    @wordpressismypuppet

    Well, the fact that you seeing the actual PHP code is the problem. It’s not being parsed by the PHP compiler. So my guess is the filename does not have a .php extension? Maybe the filename is index.htm or index.html? Renamve the file and give it a .php extension. Then it will be parsed properly and all should work.

    That worked! thank you for your help, it is much appreciated.

    wpismypuppet

    @wordpressismypuppet

    You are welcome. Please mark this post as resolved so other people know. Glad I could help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘search widget on my non-wordpress home page?’ is closed to new replies.