Skip Navigation

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.

Elementor users - please update WPML to the latest version to maintain compatibility. More details here - https://wpml.org/changelog/2024/12/wpml-4-6-15-critical-update-for-elementor-sites/
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-08:00)

This topic contains 5 replies, has 3 voices.

Last updated by Bobby 1 month, 3 weeks ago.

Assisted by: Bobby.

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
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
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
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-08: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-08: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.