Quite often, we have customers coming to us and telling us that they have some images that are not appearing on their Joomla website. After investigation, it all comes down (mainly) to three reasons:
- Joomla SEF or an equivalent URL rewrite extension
- The short_open_tag directive in php.ini
- The asp_tag directive in php.ini
Let us discuss each one of the above.
Joomla SEF causing images not to display
As a rule, the URL rewriting on the page must happen after the content is generated on the website, and before the cache. This means that under Extensions – “Manage Plugins”, you need to make sure that the order of the Joomla SEF plugin is after all the content plugins, but before the Joomla Cache plugin.
If the URL rewriting happens before that stage, then some of the URLs generated may be broken or may not be rewritten. However, the Joomla SEF is sometimes too smart even for its own good, as it tries to rewrite/manipulate URLs that are already rewritten or that do not need to be rewritten, including URLs of images. So if this thing happens, you will have broken images on your website. The solution to this problem is to search for the plugin that generates the affected content (usually it’s not a core plugin) and make sure that its ordered to be executed after the Joomla SEF runs. You might be wondering, isn’t this against the rule that we talked about earlier? It is, but then again, this is programming, and there are many, many exceptions to every rule.
How do you know instantly that the problem is related to Joomla SEF plugin?
In order to know in less than 1 minute whether the Joomla SEF plugin is the culprit, disable it, and then check if the images are now appearing, if they are, then for sure the reason for them not appearing is the URL rewriting.
short_open_tag PHP directive is set to off – but it is used
Let’s say you move your Joomla website to another (new?) server, and then you start testing it. Everything works perfectly, except that some of the images are no longer displaying. You try everything, you even disable the Joomla SEF plugin and your turn off URL rewriting, but yet the images are still not appearing. You’re lost. You then decide to check the code of your HTML page, to see how the images are linked to, and to your surprise, here’s what you see:
<img src="<? echo(YOUR_DOMAIN_URL.'/images/your_missing_image.jpg'); ?>">
You think, odd… This looks like it’s still written in PHP, why is that? Well, the reason is that the above was not parsed by the PHP parser is that it’s using something called short open tags, whereby the programmer uses <? to open the PHP tags (where he writes PHP code), instead of using the <?php . There are four ways to fix this problem:
- Open your php.ini file, search for the directive short_open_tag, and change its value to on instead of off.
- Create a local php.ini (which is a copy of the global php.ini), put it in the root directory of your website, and change the value of the short_open_tag directive to on.
- Open your index.php file in the root directory of your Joomla website and type the following (in the first line, before any code starts, but after
<?php):ini_set( "short_open_tag", 1 ); - Locate the file(s) that contains this code
<?and change it with<?php
asp_tags PHP directive is set to off – but it is used
There are programmers that have ASP background (ASP is a web scripting language developed by Microsoft) and they’re used to the ASP tags and so they write code like the following line:
<%=YOUR_DOMAIN_URL.'/images/your_missing_image.jpg'%>.
The problem though with the above line that it won’t work if the asp_tags directive is not set to on. You have 3 ways to fix this problem:
- Open your php.ini file, search for the directive asp_tags, and change its value to on instead of off.
- Create a local php.ini, put it in the root directory of your website, and change the value of the asp_tags directive to on.
- Locate the file(s) that contains this code
<%and change it with<?php
There are, of course, many other reasons for the images to disappear or not appear in the first place on your website, including:
- Wrong PHP script used to display the images
- Path to the images has changed
- Read permissions not given on the images directory
If you need any help with your Joomla website not displaying the images, then feel free to contact us. We’re always friendly, our fees are reasonable, and we’re always there!