Upcoming events widget – qtranslate-xt shortcodes not working
-
Could you give me some advice on which part of your plugin code to look at in order to make the shortcodes work for switching between languages provided by the plugin qtranslate-xt? They work perfectly fine on the main calendar page (https://dfg-lfa.org/en/termine/kalender/), but unfortunately not on the upcoming events widget in the left sidebar (https://dfg-lfa.org/). Thank you very much in advance for your support!
The page I need help with: [log in to see the link]
-
I took a look at QTranslate XT, and I think I have an idea what’s going on – can you try inserting the upcoming events list into your post content, and see if it works inside post content? If it does, then I think I’m right about the reason, but verification would be helpful.
If it doesn’t, I could still be partially right, but let me know, if you can.
I’m fairly confident it’s because the filter
the_contentisn’t run inside the upcoming events widget, and that’s what’s doing the custom tag parsing.Hi there! Thank you so much for your reply! You’re absolutely right with your assumption: When I insert the [my_calendar_upcoming] shortcode into a post, the event titles are displayed correctly, i.e. separately.
Could you tell me what needs to be done to fix the incorrect display in the sidebar widget?
-
This reply was modified 1 month, 2 weeks ago by
Mountain_King.
Well, the simplest solution would be to run
the_contentfilters on the widget output. However, that could have some fairly significant other consequences, so it’s not my first choice. It also seems like it runs onthe_excerpt, but that could also have significant side effects.I’m going to have to look at the plugin and see what other options there are. Seems like the only option is going to be to check and see if the function
qtranxf_useCurrentLanguageIfNotFoundShowAvailable()exists and run it over the content if it does, but I prefer to avoid implementing one-off plugin-specific solutions if I can find something more general.You could do it within your own site by using a custom PHP template for upcoming events lists and wrapping the rendered title/description in that function, though.
Just wanted to tell you that thanks to your guidance I was able to sort out the issue. Here’s the code I’m using on my website:
/**
* ====================================================================
* My Calendar & qTranslate-XT Integration
* --------------------------------------------------------------------
* ====================================================================
*/
/**
* 1. Text übersetzen (Titel, Beschreibung, Kurzbeschreibung etc.)
*/
function my_mc_qtranslate_apply_translation( $text ) {
// Nur ausführen, wenn qTranslate-XT aktiv ist und Text vorhanden ist
if ( function_exists( 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) && ! empty( $text ) && is_string( $text ) ) {
return qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $text );
}
return $text;
}
/**
* 2. Liste der Event-Felder, die übersetzt werden sollen
* (entsprechen den My-Calendar Template-Tags {title}, {excerpt}, ...)
*/
function my_mc_qtranslate_filter_shortcodes( $e, $event ) {
$mc_text_fields = array(
'title',
'link_title',
'linking_title',
'shortdesc',
'excerpt',
'autoexcerpt',
'description',
);
foreach ( $mc_text_fields as $field ) {
if ( isset( $e[ $field ] ) ) {
$e[ $field ] = my_mc_qtranslate_apply_translation( $e[ $field ] );
}
}
return $e;
}
add_filter( 'mc_filter_shortcodes', 'my_mc_qtranslate_filter_shortcodes', 10, 2 );Thank you very much for your support and your excellent plugin!
-
This reply was modified 1 month, 2 weeks ago by
You must be logged in to reply to this topic.