I need to change the content of a static block in magento for visitors from some special countries.

This is the JavaScript embedded into the Magento:

<script src="http://j.maxmind.com/app/country.js" charset="ISO-8859-1"></script>

I use the following code in my static block :

if (geoip_country_code() == 'GB') 
      alert("Hello, you are in Great Britain");

But when i save this static block, magento changes it to this:

<p>if (geoip_country_code() == 'GB') { alert("Hello, you are in Great Britain"); }</p>


What should i do to determine the GeoIP of the visitors and change the Content to be shown in an static block?

3 Answers 3


Here are two alternative approaches for you:

  1. You can put your JS logic into external JS file and attach it to CMS page using layout update at the "Design" tab. Then depending on you visitors country you can load the content of appropriate CMS block with ajax.
  2. I can recommend my GeoIP extension. You can use it to detect visitors country on Magento side and then add a corresponding block to your page:

    $geoIP = Mage::getSingleton('geoip/country');
    if ($geoIP->getCountry() == 'gb') {
        // show one block
    } else {
        // show another block
  • can this be used for cities or provinces/states as well?
    – SR_Magento
    Jun 9, 2014 at 14:00
  • shouldn't disable WYSIWYG? can i use this block in an static block?
    – mir.moezi
    Jun 9, 2014 at 14:34
  • @sr_magento not yet.
    – user487772
    Jun 9, 2014 at 15:19
  • @Sepano no. it has not connection to WYSIWYG at all.
    – user487772
    Jun 9, 2014 at 15:20

First of all, disable WYSIWYG editor. Better yet, make it so that WYSIWYG editor is disabled by default: System > Configuration > General > Content Management > WyYWIWYG Options > Enable WYSIWYG Editor and set it to Disabled by Default

Now that we can enter stuff directly:

<script type="text/javascript">
if (geoip_country_code() == 'GB') 
    alert("Hello, you are in Great Britain");

Save, reload page and (hopefully) enjoy results ...


what you need to do is change the logic where you are displaying the block

1.Wrap this call inside the condition,

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('geo')->toHtml() ?>

2.By your layout handler if you are calling i.e,

<block type="cms/block" name="geo">
    <action method="setBlockId"><block_id>geo</block_id></action>

and call as

$this->getChildHtml('geo') in your phtml file,

wrap this around your condition.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.