This thread is resolved. Here is a description of the problem and solution.
Problem: You need a simple language switcher with your own styling, but WPML is loading 90 default styles that you have to override. Solution: If you're implementing a custom language switcher and need to prevent WPML's default styles from loading, you can modify the code in your site. Specifically, you can edit the
Add the following code within this method to check if the constant
ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS
is defined, and if so, return nothing, effectively stopping the CSS from loading:
if (defined('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS')) {<br /> return \'\';<br />}
This solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If this does not resolve your issue, please open a new support ticket at WPML support forum.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
If you added a custom code to your functions.php file to create the language switcher, I would recommend adding an ID so you can easily change the CSS.
Thanks for coming in.
The issue is not adding or changing CSS.
This was my Question:
How can I stop these preset styles from loading?
I just don't want WPML to load any styles of it's own that I then have to work against.
I know how to do that, but it causes extra effort that I don't think should be necessary.
However, as you’ve correctly noticed, this method only affects the default language switcher in the menu. It does not apply to custom language switchers, which are not currently covered by this setting.
If you're implementing a custom switcher and need more granular control over assets, you might consider deregistering specific styles or scripts via custom code.
Thanks Carlos. Deregistering is really what I'd like to do. But since these specific styles do not seem to be registered anywhere, I would not know how to deregister.
Maybe you can put this down as a feature request, to offer a clean possibility to stop these styles from loading? I cannot imagine being the first one having issues with that.
Edit:
When this is active, then there is actually one file less loaded in the frontend:
/wp-content/plugins/sitepress-multilingual-cms/templates/language-switchers/legacy-list-horizontal/style.min.css?ver=1
Thank you very much for sharing the credentials requested.
I double-checked the HTML and the inline styles in the HTML are not coming from WPML. I consulted a colleague and he recommended checking if there is any cache memory or CSS optimizer that embeds the CSS into the HTML.
Well, I do use perfmatters, but not inlining styles, and no optimizer would do it like this, at the actual element.
The style tag contains code from this file:
wp-content/plugins/sitepress-multilingual-cms/dist/css/blocks/language-switcher.css
Not similar, it is exactly that code. So I assumed it is injected from there. And the plugin code looks like it does that. But I can't be sure ...
So I wonder if your colleague could perhaps have another look?
We tested it on a sandbox site with a minimal installation. Using this link: hidden link you can access the backend of the sandbox site.
The language switcher was added in the footer, so you can see it here: hidden link
I can see you have a multisite installation, maybe that is what's causing this behavior. However, I would recommend deactivating/activating the WPML plugins on the site and double-checking if the issue has disappeared.
Thanks for setting up the testing site. Your switcher looks like the default one, not the custom one that I am having the issue with. There is no issue with the default one, I've been able to remove the WPML CSS, too, for that one, with the forementioned constant settings.
That inline styling only appears with the custom switcher. When deactivating WPML Multilingual CMS, it is gone.