WordPress – Changing The Site URL Using WP-CLI Command Line Tool

The WP-CLI command line tool is a handy application to run various WordPress tasks.

Download the WP-CLI command line tool into the WordPress root folder using CURL or WGET.

curl -O

Check if the tool is working.

php wp-cli.phar --info

Not run the search and replace command to look through all the core tables to change the URL.

php wp-cli.phar search-replace '' ''

This will save you numerous hours and give you some peace of mind!

Et Cetera

Google AdWords Campaign / Spelling Fail – Millets Outdoor Store

I Googled “North Face Shoes“. Millets Outdoor Store flashed an advertisement, offering an additional 15% off by using a coupon code!

Millets Outdoor Store Google Adwords Ad

I clicked (costing Millet a click) the link and visited their North Face landing page. I added a North Face shoe to the basket and applied the voucher code “REDHOT“. I was greeted with an error message:

Unfortunately an error has occured
This coupon expired on 29 Jun 2015

Millets Outdoor Store Basket Voucher Code Failed

Problem 1 – Expired Voucher Code in an Advertisement

So, the voucher code expired on the 29th of June 2015. Someone must have forgotten to set up the campaign to end on the 29th of June 2015. Now they waste click costs on bringing potential customers to their website and turning them away.

Problem 2 – Spelling Mistake

Occured is a misspelling of occurred.

I do not know if Millets have an agency managing their PPC campaigns or if it is managed in-house. The above example shows us that even big brands with big agencies could fail on simple terms.


Magento – Adding a Custom Category Attribute (EAV)

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');


$setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'show_sale_icon',
        'backend'           => '',
        'default'           => 0,
        'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'group'             => 'General',
        'input'             => 'select',
        'label'             => 'Show Category Sale Icon',
        'position'          => 100,
        'required'          => false,
        'source'            => 'eav/entity_attribute_source_boolean',
        'type'              => 'int',
        'user_defined'      => true,
        'visible'           => true,
        'visible_on_front'  => true,

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');


$setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'additional_description',
        'backend'                   => '',
        'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'group'                     => 'General',
        'input'                     => 'textarea',
        'is_html_allowed_on_front'  => true,
        'is_wysiwyg_enabled'        => true,
        'label'                     => 'Additional Description',
        'position'                  => 100,
        'required'                  => false,
        'type'                      => 'text',
        'user_defined'              => true,
        'visible'                   => true,
        'visible_on_front'          => true,


Magento Fix – Email Validation for New gTLDs

Have you come across the following errors in Magento?

  • Invalid email address “[email protected]
  • [email protected]” is not a valid hostname.
  • ‘’ appears to be a DNS hostname but cannot match TLD against known list
  • ‘’ appears to be a local network name but local network names are not allowed

It is probably because the Zend email validation library is not uptodate with all the new gTLDs that are being released.


Navigate to line 539 and comment out the following lines of code. This is where the domain name is checked against an array of validTlds.

if (!in_array($this->_tld, $this->_validTlds)) {
    // $this->_error(self::UNKNOWN_TLD);
    // $status = false;
    // break;

The alternative is to add all possible TLDs into the validTlds array. I prefer the above method as I do not have to keep updating the validTlds array with hundreds of new gTLDs.


Yoast Google Analytics Reassign ‘__gaTracker’ Tracker to ‘ga’ Variable

Google Analytics by Yoast is a must have plugin for all WordPress installs. It makes adding GA trackers a breeze and it can also ping certain events to Google Analytics. The only unexplained bit of code is the issue. At some point, the ‘ga’ variable changed to ‘__gaTracker’. This raised some concerns among the techy folk.

The change affects anyone adding custom bits of Google Analytics code such as event tracking. Mostly, people would probably notice their Contact Form 7 event tracking stop working. There is a solution to this by changing all your custom trackers from ‘ga’ to ‘_gaTracker’.

The other safer way would be to remap ‘_gaTracker’ to ‘ga’ and that will allow both trackers to work. To do this, open up your Yoast Google Analytics > Settings > Advanced tab and navigate to the “Custom code:” field. Enter the following:

__gaTracker( function() { = __gaTracker;

This simply waits for ‘_gaTracker’ to be set and then assigns ‘_gaTracker’ to ‘ga’. Now, both ‘ga’ and ‘_gaTracker’ will work fine.



Magento – Reset File and Folder Permissions

You might have come across the following error while in Magento Connect Manager – Warning: Your Magento folder does not have sufficient write permissions. Magento needs certain file and folder permissions to be able to automatically performs upgrades and module installs.

Open your SSH and browse to your root folder. Then, run the following commands.

find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
chmod 777 -R downloader var media

This should set your Magento file and folder permissions to the preferred state.


Magento – Get CMS Static Block Model Data (Title, Status, Content)

You can store template and HTML data in Magento’s static blocks. If you want to pull it into your PHTML templates, just call load up the model and use the data fields.

$staticBlock = Mage::getModel('cms/block')->load('static-block-identifier');
echo $staticBlock->getTitle();
echo $staticBlock->getIdentifier();
echo $staticBlock->getIsActive();
echo $staticBlock->getContent();

Magento – Check if CMS Static Block is Enabled / Active

Static blocks in Magento are really useful. They offer an easy way to insert content into various parts of the template. You are only limited by your imagination. You can check if the static blocks are enabled, before printing them to screen.


if(Mage::getModel('cms/block')->load('static-block-identifier')->getIsActive()) :

    echo Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('static-block-identifier')->toHtml();



Magento – Get Logged In Customer’s Group ID

/* Check if customer is logged in */
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) :
	/* Get the logged in customer's group ID */
	$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
	/* Check if the logged in customer's group ID matches with the ID you are after */
	/* Customer group IDs are listed against each group under Admin > Customers > Customer Groups */
	if($customerGroupId == 3) :
		echo 'Welcome Retailer';

You can also write static blocks or custom variables to contain group specific information. You can name the static block identifier based on the $customerGroupId and retrieve it on the front end.


How to Clone a Git Repository into the Current Directory

Somehow, most examples of Git’s clone command show a subfolder for the repository to be cloned into. I, for example, prefer navigating to the desired directory and like to clone into the current directory. The Git command has to be changed to appear as follows:

git clone [email protected]:your-username/repository-name.git .

git clone .

The ‘.’ (period) indicates the current folder.