This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
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: America/Los_Angeles (GMT-07:00)
Tagged: Feature request
This topic contains 6 replies, has 3 voices.
Last updated by Guillaume Sondag 4 months, 2 weeks ago.
Assisted by: Bobby.
Author | Posts |
---|---|
October 18, 2024 at 12:34 pm #16304642 | |
nicolasG-15 |
<b>Background of the issue: </b> I'm developing a theme with custom post type recipe with custom taxonomy recipe_category on a multisite environnement with WPML & co. When I add an internal link with the visual editor of an ACF WYIWYG field, it appears differently in the front end. If I comment on lines 26 to 28 of the ACFML plugin's classes/Field/FrontendHooks.php file, it's OK. The special feature is that I have a filter on the post type link to include categories in the URL. Here's my code : /** * Replace %recipe_category% by the taxonomies slug in the recipe post type permalink. * * @source : https://stackoverflow.com/questions/66575072/wordpress-permalink-rewrite-for-custom-taxonomy-and-post-type-that-uses-parent-a * * @param string $post_link The post link. * @param object $post The post object. * * @return string The post link. */ function recipe_post_type_link( $post_link, $post ) { if ( ! is_a( $post, 'WP_Post' ) || 'recipe' !== get_post_type( $post ) ) { return $post_link; } $taxonomy = 'recipe_category'; // Handle the Yoast SEO primary term. $primary_term = get_primary_category( $post->ID, $taxonomy ); if ( $primary_term && ! is_wp_error( $primary_term ) ) { $ancestors = get_ancestors( $primary_term->term_id, $taxonomy, 'taxonomy' ); $ancestors = array_reverse( $ancestors ); $ancestors[] = $primary_term->term_id; // Add the primary term itself at the end $slug_hierarchy = []; foreach ( $ancestors as $term_id ) { $term = get_term( $term_id, $taxonomy ); if ( $term && ! is_wp_error( $term ) ) { $slug_hierarchy[] = $term->slug; } } if ( ! empty( $slug_hierarchy ) ) { $post_link = str_replace( '%' . $taxonomy . '%', join( '/', $slug_hierarchy ), $post_link ); } } else { $post_link = str_replace( '%' . $taxonomy . '%/', '', $post_link ); } return $post_link; } add_filter( 'post_type_link', __NAMESPACE__ . 'recipe_post_type_link', 10, 2 ); I think there is a conflict with it but I can't remove the wpml_translate_link_targets from ACFML plugin. The issue is already reported here : https://wpml.org/forums/topic/acfml-disable-the-auto-convert-target-links-in-wysiwyg-fields/ <b>Symptoms: </b> <b>Questions: </b> |
October 18, 2024 at 2:17 pm #16305204 | |
Laura Supporter
Languages: English (English ) Italian (Italiano ) Timezone: Europe/Rome (GMT+01:00) |
Hi, thanks for contacting us. You can try to go to \ACFML\Field\FrontendHooks::convertTargetLinks in wp-content/plugins/acfml/classes/Field/FrontendHooks.php if ( $isWysiwygField && is_string( $value ) ) { turning it to if ( $isWysiwygField && is_string( $value ) && strpos($value, 'http') !== false ) { However, please be aware this might cause performance issues, that's why we didn't fix it yet. |
October 20, 2024 at 6:24 pm #16309185 | |
nicolasG-15 |
Hi, Thank you for your reply. However, it's not a long-term solution: the next time the plugin is updated, the code will be deleted. What is the purpose of this filter? The ACF field is conditioned to be translated and not duplicated. I don't understand why it translates : [...]/custom_post_type_slug/parent_category/child_category/post_slug to [...]?=taxonomy_name=post_slug Isn't there a way of adding a filter to disable link translation in the theme by a given ACF field ? |
October 23, 2024 at 5:57 pm #16323095 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-07:00) |
Hi there, Thank you for your response. I understand your concerns about the temporary nature of the workaround, especially with upcoming plugin updates overwriting the code. This issue has been escalated to our development team to explore a more permanent solution. For now, please continue using the provided workaround if it's functioning as expected. I also recommend subscribing to the thread you mentioned, so you'll be notified as soon as there are any updates. |
October 23, 2024 at 7:05 pm #16323370 | |
nicolasG-15 |
OK, I understand. I'm staying subscribed to this thread, please let me know if there is any news. |
October 23, 2024 at 10:35 pm #16323758 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-07:00) |
Will do that, I am adding this thread to the original one. I cannot provide an eta at the moment but if there are news we will update. |
February 28, 2025 at 1:27 pm #16760988 | |
Guillaume Sondag |
Hello, I just ran into the same issue as nicolasG-15 and Chris from linked post. It's been a long time and nothing has been done to address this issue. The problem can make a lot of 404 link in all wysiwyg of a website, I find it very critical... Mostly because it is extremly difficult to identify the origin of the problem. I manage the url pattern of a CPT + Custom taxonomy manually, and thus the 'wpml_translate_link_targets' filter completely destroy hrefs inside my wysiwyg, making 404 links. As 'wpml_translate_link_targets' filter is not flexible enough with hooks inside to correct the default behaviour we should at least have an easy and clean way of disabling it. After trying multiple fix, I managed to do a fix in functions.php, which is better than updating the plugin's files, but still not as good as a feature included in the plugin. For helping others with the same problem, here's how I did it : /** * @see \ACFML\Field\FrontendHooks::convertTargetLinks * web/app/plugins/acfml/classes/Field/FrontendHooks.php * * @see \WPML_Translate_Link_Targets_Hooks::__construct * web/app/plugins/sitepress-multilingual-cms/classes/translation-management/class-wpml-translate-link-targets-hooks.php */ function disable_wpml_translate_link_targets() { global $wp_filter; if ( ! empty( $wp_filter['wpml_translate_link_targets'] ) ) { unset( $wp_filter['wpml_translate_link_targets'] ); } } add_action( 'init', 'disable_wpml_translate_link_targets' ); |