Skip Navigation

Resolved

Reported for: WPML Multilingual CMS 4.5.8

Resolved in: 4.5.9

Overview of the issue

Under certain hosting environments, you will notice that WPML’s style sheets do not load correctly. If you check the browser console, you will notice that the style sheets point to the folder /ontent/ instead of /wp-content/.  For example:

https://domain.com/ontent/plugins/sitepress-multilingual-cms/templates/language-switchers/legacy-list-horizontal/style.css?ver=1

Workaround

Make a full backup of your site before proceeding.

  1. Open /wp-content/plugins/sitepress-multilingual-cms/classes/class-wpml-file.php file.
  2. Look for line 66:
  3. Replace:
    public function get_uri_from_path( $path ) {
        $base = null;
      
        if ( $this->wp_api->defined( 'WP_CONTENT_DIR' ) && $this->wp_api->defined( 'WP_CONTENT_URL' ) ) {
            $base_path = $this->fix_dir_separator( $this->wp_api->constant( 'WP_CONTENT_DIR' ) );
      
            if ( 0 === strpos( $path, $base_path ) ) {
                $base = array(
                    'path' => $base_path,
                    'uri'  => $this->wp_api->constant( 'WP_CONTENT_URL' ),
                );
            }
        }
      
        if ( ! $base ) {
            $base = array(
                'path' => $this->wp_api->constant( 'ABSPATH' ),
                'uri'  => site_url(),
            );
        }
      
        $base['uri']   = preg_replace( '/(^https?:)/', '', $base['uri'] );
        $relative_path = substr( $path, strlen( $base['path'] ) );
        $relative_path = str_replace( array( '/', '' ), '/', $relative_path );
        $relative_path = ltrim( $relative_path, '/' );
      
        return trailingslashit( $base['uri'] ) . $relative_path;
    }
    
  4. With:
    
    	public function get_uri_from_path( $path ) {
    		$base = null;
    
    		if ( $this->wp_api->defined( 'WP_CONTENT_DIR' ) && $this->wp_api->defined( 'WP_CONTENT_URL' ) ) {
    			$base_path = $this->fix_dir_separator( $this->wp_api->constant( 'WP_CONTENT_DIR' ) );
    
    			if ( 0 === strpos( $path, $base_path ) ) {
    				$base = array(
    					'path' => $base_path,
    					'uri'  => $this->wp_api->constant( 'WP_CONTENT_URL' ),
    				);
    			}
    		}
    
    		if ( ! $base ) {
    			$base = array(
    				'path' => $this->wp_api->constant( 'ABSPATH' ),
    				'uri'  => site_url(),
    			);
    			if ( 0 !== strpos( $path, $base_path ))
    			{
    				$search = (WPML_PLUGIN_PATH);
    				$pathexplode = explode($this->wp_api->constant( 'DIRECTORY_SEPARATOR' ), WPML_PLUGIN_PATH);
    				$pathexplode = array_slice($pathexplode, -3, 3, false);
    				$replace = $pathexplode[0] .$this->wp_api->constant( 'DIRECTORY_SEPARATOR' ) . $pathexplode[1].$this->wp_api->constant( 'DIRECTORY_SEPARATOR' ).WPML_PLUGIN_FOLDER;
    				$base["path"] = str_replace ($replace, "", $search);
    			}
    		}
    
    		$base['uri']   = preg_replace( '/(^https?:)/', '', $base['uri'] );
    		$relative_path = substr( $path, strlen( $base['path'] ) );
    		$relative_path = str_replace( array( '/', '\' ), '/', $relative_path );
    		$relative_path = ltrim( $relative_path, '/' );
    
    		return trailingslashit( $base['uri'] ) . $relative_path;
    	}
    

2 Responses to “WPML's style sheets point to /ontent/ instead of /wp-content/”

  1. I think the best workaround until the issue is solved is to dequeue the plugin css script and enqueue it again with the correct path instead of editing the plugin files.


    /**
    **************** Temp fix
    */
    add_action( 'wp_enqueue_scripts', 'wpml_bitnami_temp_fix', 9999 );
    function wpml_bitnami_temp_fix() {
    wp_dequeue_style( 'wpml-menu-item-0' );
    wp_enqueue_style( 'wpml-menu-item-0-temp', '[url]/wp-content/plugins/sitepress-multilingual-cms/templates/language-switchers/menu-item/style.min.css?ver=1' );
    }

    • Thank you for sharing your approach @mohammeda-24. Keep in mind that it should be done for any style loaded.