• Hi All,

    I was hoping that somebody could help me with this. I’m looking for a way to disable the search function for visitors that visit my site, but logged in users can still have the ability to search posts.

    So basically:

    Visitors: Search disabled
    Logged in users: Search enabled

    Thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • Any particular reason you don’t want visitors to search for posts? It seems a bit odd.

    One possible way would be to code up your searchform.php template file like so:

    <?php if ( is_user_logged_in() ) {
     /*
     Your standard search form code goes here
     */
    }
    ?>

    This would make the search form only available to logged in users.

    Thread Starter dthrevan

    (@dthrevan)

    Thanks for this, the reason why i want searching disabled for visitors is because the site is being used as an intranet and requires users to be authenicated to view the posts.

    Thread Starter dthrevan

    (@dthrevan)

    this didn’t work

    Thread Starter dthrevan

    (@dthrevan)

    here is the code of my searchform.php

    <?php if ( is_user_logged_in() ) {
    <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
            <input type="text" value="<?php _e("Search...", "framework") ?>" name="s" id="s" onblur="if (this.value == '')  {this.value = '<?php _e("Search...", "framework") ?>';}" onfocus="if (this.value == '<?php _e("Search...", "framework") ?>')
    {this.value = '';}" />
    </form>
    }
    ?>
    Thread Starter dthrevan

    (@dthrevan)

    anyone?

    <?php if ( is_user_logged_in() ) { ?>
    <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
            <input type="text" value="<?php _e("Search...", "framework") ?>" name="s" id="s" onblur="if (this.value == '')  {this.value = '<?php _e("Search...", "framework") ?>';}" onfocus="if (this.value == '<?php _e("Search...", "framework") ?>')
    {this.value = '';}" />
    </form>
    <?php }
    ?>

    Close the PHP statements before the html blocks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Disable seach for visitors’ is closed to new replies.