Você está em boa companhia com suporte incrível 🤝

Proteção contra hotlinking de imagens

Bloqueia o uso de suas imagens em outros sites via .htaccess ou funções WordPress.

Time Full Services Time Full Services
PHP
/**
 * Via wp_headers (PHP)
 */
add_filter('wp_headers', function (array $headers): array {
  if (is_attachment() || (isset($_SERVER['REQUEST_URI']) && preg_match('/.(jpg|jpeg|png|gif|webp|svg)$/i', $_SERVER['REQUEST_URI']))) {
    $referer  = $_SERVER['HTTP_REFERER'] ?? '';
    $meu_host = parse_url(home_url(), PHP_URL_HOST);

    if ($referer && !str_contains($referer, $meu_host)) {
      status_header(403);
      exit;
    }
  }
  return $headers;
});

/*
 * Ou via .htaccess:
 *
 * RewriteEngine on
 * RewriteCond %{HTTP_REFERER} !^$
 * RewriteCond %{HTTP_REFERER} !^https://(www.)?meusite.com.br/ [NC]
 * RewriteRule .(jpg|jpeg|png|gif|webp|svg)$ - [NC,F,L]
 */

Seja PRO.

Tenha acesso a snippets de código premium — PHP, JavaScript, CSS e HTML prontos para usar em seus projetos.

Conhecer o plano Pro →