Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter csit

    (@calmsmile)

    I found the way to change the url on WPML side, but Ultimate Member since no hook to change the “View profile” link

    here is my code in my themes functions.php:

    if ( function_exists('icl_object_id') ){
    		$languages = icl_get_languages('skip_missing=0&orderby=code');
    		if(!empty($languages)){
    			html = ''; 
    			foreach($languages as $l){
    				if(!$l['active'] || $l['active'] ) {
    					if( $l['code'] === 'en'){
    						$url = str_replace('?lang=en', '', $l['url']);
    						$url = untrailingslashit( $url ).'?lang=en';
    					}else{......

    on this way I change the WMPL switcher to the correct link, but the “View profile” link can not change

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @calmsmile

    You can use this filter hook to modify the profile URL:
    um_localize_permalink_filter

    example usage:

    add_filter("um_localize_permalink_filter","um_010822_profile_url");
    function um_010822_profile_url( $profile_url ){
     
       if ( function_exists('icl_object_id') ){
            $languages = icl_get_languages('skip_missing=0&orderby=code');
            if(!empty($languages)){
    	    foreach($languages as $l){
    		 if(!$l['active'] || $l['active'] ) {
    		     if( $l['code'] === 'en'){
    			 $profile_url = str_replace('?lang=en', '', $profile_url);
    			 $profile_url = untrailingslashit( $profile_url ).'?lang=en';
                         }
                     }
                }
            }
       }
       return $profile_url;
    }

    Regards,

    Thread Starter csit

    (@calmsmile)

    Hi @champsupertramp Thanks for your code! I have try to use it ,but still no change, even I test it like this:

    add_filter("um_localize_permalink_filter","my_um_profile_url", 10, 2);
    function my_um_profile_url( $profile_url){
             $url = $profile_url;
    	 $url = str_replace('?lang=en', '', $url);
    	 $url = untrailingslashit( $url ).'?lang=en';
    
            return $url
    }

    the result is : https://192.168.9.168:89/user?lang=en/qq122649529sdaf/

    It seems that the part of username is added after this filter

    • This reply was modified 3 years, 2 months ago by csit.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @calmsmile

    Could you please try changing the priority number to 20?

    add_filter("um_localize_permalink_filter","my_um_profile_url", 20, 2);
    function my_um_profile_url( $profile_url){
             $url = $profile_url;
    	 $url = str_replace('?lang=en', '', $url);
    	 $url = untrailingslashit( $url ).'?lang=en';
    
            return $url
    }

    Regards,

    Thread Starter csit

    (@calmsmile)

    I have try, but the result is still the same, the user name always after the ?lang=en
    the result: https://192.168.9.168:89/user?lang=en/qq122649529sdaf/
    even I try return nothing:

    add_filter("um_localize_permalink_filter","my_um_profile_url", 20, 2);
    function my_um_profile_url( $profile_url){
    //nothing to return
    return;
    }

    the “View profile” link output: <a href="/qq122649529sdaf/">View profile</a>

    the username “/qq122649529sdaf/” always added to the View profile, even the “um_localize_permalink_filter” return empty

    • This reply was modified 3 years, 2 months ago by csit.
    • This reply was modified 3 years, 2 months ago by csit.
    • This reply was modified 3 years, 2 months ago by csit.
    • This reply was modified 3 years, 2 months ago by csit.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @calmsmile

    I just checked that this filter hook um_localize_permalink_filter doesn’t have the slug/username. It adds the slug/username after the filter hook happened. For now, I suggest that you use the “Different languages in directories” ( yoursite.com/en/user/myusername/ ) permalink format. Please go to WP Admin > WPML > Languages > Language URL format > “Choose how to determine which language visitors see contents in” > choose “Different languages in directories “.

    We are working on version 3.0 that will fully support WPML.

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @calmsmile

    ..Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WPML duplicate the username for profile url’ is closed to new replies.