Home / comment / Deny comment no referrer requests
  • How to Deny comment no referrer requests

    deny-comment-no-referrer-requests

    Adding this PHP code to the functions.php will check the referrer when a user posts a comment to ensure they are not a BOT. Thanks to Joost de Valk for this little snippet,

    ( click code to copy )

    wordpress snippet : PHP

    <>
    function check_referrer() {
       if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == “”) {
           wp_die( __(‘Please enable referrers in your browser, or, if you\’re a spammer, bugger off!’) );
       }
    }
    add_action(‘check_comment_flood’, ‘check_referrer’);
    

    ( WordPress codex functions, hooks, in this snippet. )

    check_comment, add_action, __, wp, wp_die,