Magento Remove Hard Coded URLs from Theme

If you are working on a theme, you may find that there are hard coded links dotted all over the place.

This can make testing a site offline (and thereby not on the same URL) a bit of a pain.

Here is a quick fix for you:

  1. Remove all hard coded links from the CMS section:
update cms_block set content = replace(content, '', '{{store url=''}}');
update cms_page set content = replace(content, '', '{{store url=''}}');
  1. Remove all hard coded links from the theme files.

This is a command line one using grep and sed.

Firstly, cd into the root theme folder

cd app/design/frontent/default/hardtheme

Now find files with hard coded links

grep -rl '' ./

Now to automatically remove all those,

grep -rl '' ./ | xargs sed -i 's/http:\/\/\//<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>/'

Tags: linksdesignmagentothemegrepcmshard codedsed