Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're developing a theme with a custom post type and custom taxonomy, and you're using the ACF WYSIWYG field in a multisite environment with WPML, you might notice that internal links appear differently in the front end. This issue could be related to a conflict with the

wpml_translate_link_targets

filter in the ACFML plugin, particularly if you have a filter on the post type link to include categories in the URL.
Solution:
We recommend updating to the latest version of WPML. Please go to Plugins > Add new, click on the "Commercial" tab, and then click "Search for WPML Updates". Install and activate the latest versions of our plugins and check if the issue persists. If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your case, please visit our known issues page and confirm that you have installed the latest versions of themes and plugins. If the problem continues, we highly recommend opening a new support ticket at WPML support forum.

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.

Tagged: 

This topic contains 10 replies, has 3 voices.

Last updated by Andreas W. 1 week, 4 days ago.

Assisted by: Andreas W..

Author Posts
October 18, 2024 at 12:34 pm #16304642

nicolasG-15

<b>Background of the issue: </b>
Hello,

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>
Internal are modified in WYSIWYG ACF Field by ACML plugin.

<b>Questions: </b>
There is a way to remove the filter applied on line 26 to 28 of the file classesFieldFrontendHooks.php ?

front.png
back.png
October 18, 2024 at 2:17 pm #16305204

Laura
WPML Supporter since 05/2018

Languages: English (English ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02: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
add an extra condition to:

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
WPML Supporter since 04/2015

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
WPML Supporter since 04/2015

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.
Do you have any updates about that ?

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' );
June 4, 2025 at 1:23 pm #17106604
nicolasG-15

Hello,

Have you fixed the problem or provided a temporary solution?

All links in translations are in 404. Including in WYSIWYG Classic editor or Gutenberg.

For information in staging website the bug doesn't appear. Bellow the versions of WordPress and plugins :

- WordPress - 6.7.2
- Advanced Custom Fields Multilingual - 2.1.4.2.
- Contact Form 7 Multilingual - 1.3.1.
- WPML Media Translation - 2.7.4.
- WPML Multilingual CMS - 4.6.13.
- WPML SEO - 2.1.0.1.
- WPML String Translation - 3.2.14.

New threads created by Andreas W. and linked to this one are listed below:

https://wpml.org/forums/topic/split-modification-of-internal-links-in-gutenberg/

June 5, 2025 at 7:26 pm #17112071

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

My colleague Bobby is currently on vacation which is why I am assisting you today.

The reported ACFML issue was fixed in WPML 4.7.

Please go to Plugins > Add new and click on the "Commercial" tab.

Click "Search for WPML Updates".

Install and activate the latest versions of our plugins.

Now, please test if you can still replicate the reported issue and let me know the results.

Best regards
Andreas

June 5, 2025 at 8:19 pm #17112289

nicolasG-15

Hello,

Indeed it's fixed for ACF fields but as I said, the problem is in Gutenberg and classic editor (WYSIYWG fields) now.

Best regards,

Nicolas

June 5, 2025 at 9:18 pm #17112455

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

This would be the topic of a new ticket.

I will split this request into a new ticket and follow up with you shortly.