Support » Developing with WordPress » Set correct Hook-Filters

  • Hi

    I have an issue with some translations on my website.

    The main issue is, that some links in the translation are not translated correctly.
    For example, parts of the URL’s in the translated languages stay in the main language, which causes a 404 error on the translated websites.

    I already managed to fix some of the links with PHP. The code checks if the URL contains the slug for the language it’s currently in and replaces the broken links:

    
    add_filter('the_content', 'fr_cherche_translation', 12, 1);
    	function fr_cherche_translation($content){
        		global $post;
    			$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        			if (strpos($url,'/fr/cherche/') !== false) { 
            		$string = "de/suche";
            		$replace = "fr/cherche";
            		$content = str_replace( $string, $replace, $content );
    			}
    	return $content;
    }
    

    That works pretty well, exept it only works for HTML-code that is inside of the “the_content” hook.
    I haven’t managed to find a hook that works for the following three cases:

    1.
    On the google-maps page on the link I provided, there is still /fr/suche/ instead of /fr/cherche/ when you click on the pin and then on the link to the location. I need to have a hook to manipulate that part of the embeded google-maps, but couldn’t find one that works.

    2.
    The other one is in the language switch on top. There I need to replace /it/suche/ with /it/cerca/. The language switch is embeded with the theme-function (I’m using BeTheme) Top bar right -> WPML.

    3.
    The third one is visible on the homepage. There I need to change the string “Search” in the search field with the proper term in the current language. The sidebar is embeded via widgets.

    I hope you guys can help me out with this.
    Would be great if i could solve it with hooks but if there’s another soution that would be much appreciated too.
    Thanks a lot in advance.

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

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    To alter URLs in various page elements, you’d need to examine the code responsible for their output. There may or may not be a hook available for your use. If none are available, you could rely upon JavaScript to update the URLs once the page loads. The script should be able to accomplish this before the user tries to use the URL.

    Updating URLs after the fact is a “band-aid” solution. It’ll work in a pinch, but it’s not ideal. Better would be for the URLs to be correctly generated to start with. This would be up to WPML. You might ask through their dedicated support forum how to best accomplish this.

Viewing 1 replies (of 1 total)
  • The topic ‘Set correct Hook-Filters’ is closed to new replies.