Support » Everything else WordPress » Having a little fun with my visitors using the search form

  • A while back I had installed Search Meter on several of my blogs — mainly to see what my visitors were looking for. This has come in very handy on my cooking blog — if I see searches for a dish I don’t have, I hit my cookbooks or the net until I find something. 🙂

    I check my Search Meter results just about every day to see what my visitors look for most. On my domain, I see a lot of searches by what are probably spam bots, for porn related crap. However, I also happen to know of several friends who regularly come on and search for certain keywords looking for dirty jokes. (Hey, sometimes I get a wild hair and post something naughty if it’s REALLY funny ;))

    I decided to customize my search page a bit to show a custom message at the top of the search results or “not found” message for certain topics — and maybe have a little fun with my visitors. 😉

    At the top of my index.php I added the following:

    $searchval = \"\";
    	$searchval = $_GET[\"s\"];
    	$searchval = $_POST[\"s\"];
    // Not necessary I know, but I get both by habit.
    $pron = eregi(\"(PATTERN)\",$searchval);
    // Above, replace PATTERN with naughty words separated by pipes
    $pronmsg = \"<h2>*** Notice ***</h2><p><strong>It appears that you are looking for adult subject matter. \";
    $pronmsg .= \"This kind of material is not present on this site. \";
    $pronmsg .= \"You are probably a spam bot - your IP and complete header information have been logged.</strong></p>\";
    $continuemsg = \"<p>&nbsp;</p><p><em>If you are not, my apologies \";
    $continuemsg .= \"... continue on with your search ... </em></p><p>&nbsp;</p><hr /><p>&nbsp;</p>\";

    And under the elseif( is_search() bit, I add:

    			if ($pron) {
    				echo \"$pronmsg\";
    				echo \"$continuemsg\";

    I added the continuemsg ~just in case~ it’s a valid search … I don’t want to embarrass them too much. 😉

    And on down where the “Not Found” message is, I replaced that couple of lines with:

    			if ($pron) {
    				echo \"$pronmsg\";
    			} else {
    				echo \"<h2>Not Found</h2><p>Sorry, but you are looking for something that isn't here.</p>\";

    This can easily be modified to handle any topic … I’m in the process now of adding one for swear words with a “Does your Mom know you look this stuff up?” message at the top. *grins*

    Just wanted to share in case anyone else had wanted to do this … or hadn’t thought to. *grin*

  • The topic ‘Having a little fun with my visitors using the search form’ is closed to new replies.