Skip Navigation

[Gelöst] image caption

This support ticket is created vor 5 Jahren, 10 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Dieses Thema enthält 21 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Waqar vor 5 Jahren, 10 Monaten.

Assistiert von: Waqar.

Author
Artikel
#1189510

yes , waiting,

#1189512

hi, are you on holiday or something?
if yes i don't want to disturb you either.

#1189513

Hi Dee,

Thank you for waiting and no I'm not on holidays.

I did some research and WordPress offers some relatively newer functions, which can be used to first get the ID of image attachment and then it's caption text:

1. attachment_url_to_postid - https://developer.wordpress.org/reference/functions/attachment_url_to_postid/

2. wp_get_attachment_caption - https://developer.wordpress.org/reference/functions/wp_get_attachment_caption/

The shortcode code can be updated to:


add_shortcode( 'ts_caption_new', 'ts_caption_new_func');
function ts_caption_new_func($atts)
{
	$url = $atts['url'];

	$image_id = attachment_url_to_postid( $url );

	if($image_id > 0) {
		$image_caption = wp_get_attachment_caption($image_id);
	}
	if ($image_caption) {
		return $image_caption;
	}
}

This approach is better than querying data directly from the database and should improve performance too.

Please let me know how it goes.

regards,
Waqar

#1189514

Hi. the solution is not working for swiper but working on flickity slider. , pls feel free to test on my site.

#1189538

Hi Dee,

I noticed that in your content template "DV Swiper Slider" ( versteckter Link ), a very long content was wrapped inside a conditional block, which is not recommended.
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ )

I've broken it down into smaller chunks and the shortcodes inside are now working from that template too. I'm sorry, I should've spotted that issue earlier and this seems to be the reason why I was not able to reproduce this on my own test website.

regards,
Waqar

#1189551

My issue is resolved now. Thank you Waqar .

#1189567

Thanks for the update Dee and glad the issue is resolved now.

Note: You can also close the other ticket, related to this topic:
https://toolset.com/forums/topic/caption-is-not-working-for-multiple-image-field-for-more-then-3-images/

regards,
Waqar