I am trying to customize the the category list of my website. So I have a menu option that shows the list of all article is a certain category. In this list I would like to show the into image of the article too. But unfortunately I cannot find the path of this intro image of each article to put it in the '' tag.

This code takes the first image in the article. Which is not what I want.

$text = $article->introtext;
if(preg_match('/<\s*img[^>]+>/Ui', $text, $matches)){

   $text = str_replace($image,'',$text);
if ($matches) {
$image = str_replace('img src="','img width="150px" src="/demo/persianlondon/',$image);
$image = str_replace("caption","", $image);
echo '' . $image . '';
else {echo '<img width="150px" src="http://goo.gl/k47rNN" class="defaultArticleImage" />';}


So I need to get the intro image url and set it for $image. Any idea to do it?

  • To give your question context, please provide some sample data and your expected result. What does $article->introtext contain? I am sure I can provide you with an optimized solution if you can clarify the posted question. Commented Nov 30, 2018 at 1:10

3 Answers 3


That code is looking in the article text you need to is in the images call. It is json encoded so you have to decoded it first.

$images  = json_decode($this->item->images);

echo $images->image_intro;

Have a look at the com_content/article/default.php template to see some of the other parts of data you can use for images.

  • Thank you for you post. I just couldnt get it working. Can you provide the full code, or just tell me where should I add it to?
    – Danial
    Commented Jul 31, 2014 at 15:08
  • 1
    Try variations on the object as I am not sure the code in the template you are using: $article->images or $item->images or $article->params->get('images') it will be around there somewhere on the main object Commented Sep 13, 2014 at 22:30
  • The above is what I used. Don't forget to add the php tags obviously. I did it this way. <?php $images = json_decode($this->item->images); $introImage = $images->image_intro; ?> ...src="<?php echo $introImage ; ?>"....
    – Eoin
    Commented May 24, 2016 at 16:38

I had the same problem on twitter. I was trying to add my link picture just as facebook does automatically but had to investigate the CARD Validator here https://cards-dev.twitter.com/validator ...Tthe way I have it working on Joomla 3.9.11 is adding this code in the head of my template default.php ... I was able to properly add the title, the description and the right picture, usually the first one on the article.


//Added for TWITTER
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $theArticle = $article->get("title");
    $theImages = $article->get("images");   
    $pictures = json_decode($theImages); // Split the parameters apart
    $timage= "http://yourdomain.com/".$pictures->{'image_intro'};
$doc =& JFactory::getDocument();
$doc->addCustomTag( '
<meta name="twitter:title" content="'.mb_strimwidth(strip_tags($theArticle),0,225, " ...").'"=""/>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="yoursite">
<meta name="twitter:creator" content="yourcreator">
<meta name="twitter:url" content="'.JURI::current().'">
<meta name="twitter:description" content="'.mb_strimwidth(strip_tags($doc->getMetaData( 'description' )),0,225, " ...").'"=""/>
<meta name="twitter:image" content="'.$timage.'">
    <jdoc:include type="head" />
    <?php $this->loadBlock('head') ?>

  • 1
    Thank you for sharing Luis and welcome to JSE. Please take the tour when you can. I recommend that you either remove the if statement if it is unnecessary, or add the $doc->addCustomTag() block inside of it. If you are coding on a "good" IDE, it will be flagging your code to state that some variables are potentially undeclared. Also, if you know that there will be a : in the id string, $article_id = strstr(JRequest::getString('id'), ':', true); is a more direct technique than creating a temporary array and accessing the first element. Consider these notes: 3v4l.org/qvj0M Commented Oct 12, 2019 at 1:29
  • Thank you, while not an expert, but solved it using many variations of what I saw in different posts. But none address all the variables, pictures, text, etc. If you can fix it, I will correct my post, but it works great for me. Sometimes need to validate de CARD before it gets the picture posted, but once it validates, Twitter adds it automatically. I Guess its because nobody post the link before, but once its there, then it picks it up all the time. Best regards ! Commented Oct 29, 2019 at 1:56

The above works for me in the category blog view, it might be different in category list view. Don't forget to add the php tags obviously. You could always use <?php // print_r($images); ?> to print all of the available options which might give you a clue. Or potentially this <?php // print_r($this->item); ?>

I did it this way.

$images         = json_decode($this->item->images); 
$introImage   = $images->image_intro;

...src="<?php echo $introImage ; ?>"....

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.