Skip to content
  1. Extras
  2. CrawlerDetect
  3. Snippets
  4. isCrawler

isCrawler snippet ​

Detects whether the visitor is a bot. Without &userAgent JayBizzle concatenates headers: HTTP_USER_AGENT, HTTP_FROM, HTTP_SEC_CH_UA, and the rest of its list.

Returns: "1" (bot) or "0" (not bot).

Call uncached: [[!isCrawler]] (MODX) or $modx->runSnippet('isCrawler', []) (Fenom). Otherwise the result is shared across visitors.

Parameters ​

ParameterDescriptionDefault
userAgentExplicit string. Empty: JayBizzle headers from the request—
placeholderPrefixPlaceholder prefix for detected bot namecrawlerdetect.

When a bot is detected, placeholder crawlerdetect.matches (or your prefix) is set to the bot name, e.g. Googlebot. Use it when debugging.

Examples ​

Show widget to humans only ​

modx
[[!isCrawler:eq=`0`:then=`[[$chatWidget]]`]]
fenom
{if $modx->runSnippet('isCrawler', []) == '0'}
  {$modx->getChunk('chatWidget')}
{/if}

Don’t load analytics for bots ​

modx
[[!isCrawler:eq=`0`:then=`[[$googleAnalytics]]`]]
fenom
{if $modx->runSnippet('isCrawler', []) == '0'}
  {$modx->getChunk('googleAnalytics')}
{/if}

Different content for bot and human ​

modx
[[!isCrawler:eq=`0`:then=`[[$fullContent]]`:else=`[[$liteContent]]`]]
fenom
{set $isBot = $modx->runSnippet('isCrawler', [])}
{if $isBot == '0'}
  {$modx->getChunk('fullContent')}
{else}
  {$modx->getChunk('liteContent')}
{/if}

Debug: which bot was detected ​

modx
[[!isCrawler]]
[[+crawlerdetect.matches]]
fenom
{$modx->runSnippet('isCrawler', [])}
{if $modx->getPlaceholder('crawlerdetect.matches')}
  Bot: {$modx->getPlaceholder('crawlerdetect.matches')}
{/if}