• Resolved mikewinsc

    (@mikewinsc)


    I have used the CRP plugin for a few months now. I noticed recently that I was having more and more internal broken links on SEM Rush. After further analysis, it looks like CRP is showing related posts in another language and not using the correct link for them.

    In the example given: https://www.196flavors.com/es/brasil-creme-de-papaya-crema-de-papaya/ shows the French version of the same post as a related post, except with an incorrect URL (https://www.196flavors.com/bresil-creme-de-mamao-creme-de-papaye/)

    When the related posts are from the same language as the original post, it is fine. The problem occurs when the posts are from another language. Those related posts in another language should not even be included to begin with. How can this be fixed? How can we tell CRP to ONLY include related posts in the same language?

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Ajay

    (@ajay)

    Could you please try this to see if it works?

    https://gist.github.com/ajaydsouza/9b1bc56cec79295e784c

    Thread Starter mikewinsc

    (@mikewinsc)

    Thanks so much, Ajay! So, I may need some additional guidance here. Where does this code go? Is there a file named same-language.php somewhere? If not, where do I create, and also curious how it will be picked up by CRP?

    Plugin Author Ajay

    (@ajay)

    You’ll need to add that code in your theme’s functions.php file which would be the best place to add it.

    Thread Starter mikewinsc

    (@mikewinsc)

    Got it. Thanks a lot, Ajay!

    Hi @ajay and thanks for the plugin!
    I’ve tried to add that code on the functions.php but similar posts are still mixed language. Please check out this post example:

    https://thefoodellers.com/en/things-to-do-mauritius

    In the similar posts box there are posts in italian…

    Thread Starter mikewinsc

    (@mikewinsc)

    @ajay We did apply the code to our staging environment and we are still seeing the same issue. Do you have any other suggestions?

    https://wordpress-145745-1214197.cloudwaysapps.com/es/brasil-creme-de-papaya-crema-de-papaya/

    You can see that the suggested French post does not have the /fr/ prefix in the URL, therefore creating a broken link.

    Ideally, I would ONLY want suggest related posts in the same language ONLY (here Spanish in /es/ folder)

    Plugin Author Ajay

    (@ajay)

    I’m looking at the documentation of WPML again and I think the CRP implementation is outdated. I don’t have access to WPML, but would you be able to make edits to my plugin code as a test?

    crp_object_id_cur_lang needs to be replaced with the below.

    
    function crp_object_id_cur_lang( $post_id ) {
    
    	$return_original_if_missing = false;
    	$post = get_post( $post_id );
    
    	/**
    	 * Filter to modify if the original language ID is returned.
    	 *
    	 * @since   2.2.3
    	 *
    	 * @param   bool    $return_original_if_missing
    	 * @param   int $post_id    Post ID
    	 */
    	$return_original_if_missing = apply_filters( 'crp_wpml_return_original', $return_original_if_missing, $post_id );
    
    	// Polylang implementation.
    	if ( function_exists( 'pll_get_post' ) ) {
    		$post_id = pll_get_post( $post_id );
    	}
    
    	// WPML implementation.
    	$post_id = apply_filters( 'wpml_object_id', $post_id, $post->post_type, $return_original_if_missing );
    
    	/**
    	 * Filters object ID for current language (WPML).
    	 *
    	 * @since   2.1.0
    	 *
    	 * @param   int $post_id    Post ID
    	 */
    	return apply_filters( 'crp_object_id_cur_lang', $post_id );
    }
    
    Thread Starter mikewinsc

    (@mikewinsc)

    Hey @ajay , we tried this and it didn’t help. What would be the best way for me to give you access to our staging environment since you will have access to WPML too. My email is mike at 196flavors

    Plugin Author Ajay

    (@ajay)

    @mikewinsc,

    I’ll drop you an email.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Compatibility with WPML’ is closed to new replies.