What is the equivalent of {{media url="wysiwyg/image.jpg"}} which can be used in CMS pages if we want to use this in a normal .phtml file (of the type core/template)


The rendering of this such URLs is done when displaying CMS pages or blocks in


public function mediaDirective($construction)
    $params = $this->_getIncludeParameters($construction[2]);
    return Mage::getBaseUrl('media') . $params['url'];

Base on this code, just an

<img src="<?php echo Mage::getBaseUrl('media') ?>image.jpg">

can be used in the template

  • 2
    Just remove the blockquote(`) from the second code snippet (after ?>image.jpg">). (I can't edit less than 6 letters) – Himanshu Jansari Sep 21 '13 at 8:13
  • 2
    +1 But it may be better to pass Mage_Core_Model_Store::URL_TYPE_MEDIA instead of 'media'? – Nick Rolando Nov 11 '14 at 21:04

In a phtml template file:

Mage::getBaseUrl('media') . $url;

In a CMS block or page:

{{store direct_url="media/url"}}

The difference between {{media url="foo"}} and {{store direct_url="media/foo"}} is that the latter hardcodes the media directory path as media.
That might lead to issues when using a CDN or something, because it bypasses Mage::getBaseUrl('media').

  • what is the difference between {{store direct_url="media/url"}} and {{media url="foo"}} ? – Alex Jun 14 '13 at 15:04
  • Updated my answer accordingly. – Vinai Jun 14 '13 at 15:07
  • Thank you. I also edited my question to make it more clear - I want the full URL of a picture. Actually I would be happy to accept my own answer ;-) --- as I know my problem best :-P – Alex Jun 16 '13 at 12:07
  • 4
    Note that: {{store direct_url="media/url"}} -> If mod_rewrite is disabled, this may introduce the index.php in the url, hence breaking the media url. – MagePsycho Jun 16 '13 at 12:15
  • 1
    @MagePsycho: good point. Lucky I've never had ha store with mod_rewrite disabled. – Vinai Jun 16 '13 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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