Skip Navigation

Open

Reported for: WPML Multilingual CMS 4.6.13

Topic Tags: Bug

Overview of the issue

There’s a known issue where relative links display incorrectly in WYSIWYG fields when a Custom Post Type and a Taxonomy share the same slug. This causes the links to revert to a query string format on the frontend, diverging from the expected pretty permalink structure.

For example, a link that should lead to http://domain/test/post-type/test-cpt/, points to http://domain/?taxonomy-test-post-type=test-cpt instead.

Workaround

You can add this snippet to your functions.php file:

/**
 * Temporary snippet: Replaces relative links with absolute links
 * before it get converted by the filter `wpml_translate_link_targets`.
 *
 * @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmldev-3478
 */
add_filter( 'wpml_translate_link_targets', function( $value ) {
    return preg_replace_callback( '/href="([^"]+)"/i', function( $matches ) {
        if ( false === strpos( $matches[1], '://' ) ) {
            $url = site_url( $matches[1] );
        } else {
            $url = $matches[1];
        }

        return 'href="' . $url . '"';
    }, $value );
}, 0 );

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>