- Posts: 18
COMMUNITY FORUM
how to change alt tag from k2 image?
- luis
-
Topic Author
- Offline
- New Member
im talking about the main image taken from the media folder (itemimage), not the other ones you can put inside the article
thx
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
In the alt tag you need to use $this->item->title;
This post will help you with overrides:
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please Log in or Create an account to join the conversation.
- luis
-
Topic Author
- Offline
- New Member
- Posts: 18
isnt that code $this->item->title; going to put the title (of the article) like alt tag??
ty
Please Log in or Create an account to join the conversation.
- Mr_Anonymous
-
- Offline
- Premium Member
- Posts: 92
Please Log in or Create an account to join the conversation.
- luis
-
Topic Author
- Offline
- New Member
- Posts: 18
ty
Please Log in or Create an account to join the conversation.
- Mr_Anonymous
-
- Offline
- Premium Member
- Posts: 92
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- luis
-
Topic Author
- Offline
- New Member
- Posts: 18
i want to customize alt because of seo of images
Please Log in or Create an account to join the conversation.
- luis
-
Topic Author
- Offline
- New Member
- Posts: 18
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
This has to be done in your item.php file of course.
Please Log in or Create an account to join the conversation.
- Goran Nešić
-
- Offline
- New Member
- Posts: 3
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
github.com/getk2/k2/blob/master/components/com_k2/templates/default/item.php#L203
Remember to use overrides:
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please Log in or Create an account to join the conversation.
- Goran Nešić
-
- Offline
- New Member
- Posts: 3
Krikor wrote: The (default) code should look like this:
github.com/getk2/k2/blob/master/components/com_k2/templates/default/item.php#L203
Remember to use overrides:
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Hello Krikor I have changed the code but still it is displaying image real name on hover with mouse instead or article name. I am making mistake somewhere.
Here is override I have created for this in my template:
<?php if($this->item->params->get('itemImage') && !empty($this->item->image)): ?>
<!-- Item Image -->
<div class="itemImageBlock">
<span class="itemImage">
<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->title)) echo K2HelperUtilities::cleanHtml($this->item->title); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
</span>
<?php if($this->item->params->get('itemImageMainCaption') && !empty($this->item->title)): ?>
<!-- Image caption -->
<span class="itemImageCaption"><?php echo $this->item->title; ?></span>
<?php endif; ?>
<?php if($this->item->params->get('itemImageMainCredits') && !empty($this->item->image_credits)): ?>
<!-- Image credits -->
<span class="itemImageCredits"><?php echo $this->item->image_credits; ?></span>
<?php endif; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
Thank you again!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Replace the contents of the title tags on the <img> element with the ones of the alt tag.
eg:
... title="<?php if(!empty($this->item->title)) echo K2HelperUtilities::cleanHtml($this->item->title); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" />
Please Log in or Create an account to join the conversation.