Widgets, WPML and Timber

I’m a big fan of Timber, a WordPress plugin which compiles Symfony’s templating language Twig into php code.

If you use Timber you can now render all your output in a Twig file, instead of having to echo the logic and all elements in a the (php) widget file.

Something like this:

which makes for cleaner template files.

So far no issues.

WPML

If you have a multilingual site, that’s where you might run into some issues.

If you have made a simple widget, which doesn’t have any widget options like widget title or another setting, you might think you don’t need the form and update option which are defined in the default usage of the widget.

That’s where you’re wrong, and so was I. If you use WPML, a widget ‘needs’ a setting in which language(s) it needs to be shown. And to store that you need a form and an update function.

So regardless if you want to use any options in your widget, ALWAYS include the form and update methods. Even if they’re empty. See below.

Then add the widget to your widget area. If you have WPML installed you’ll see an option to show the widget in a particular language or all. Save it for a particular language, then change it back to all languages and save it again.

Why these steps ? I have noticed and deduced (with WPML support) if you save it on the first save with all languages, it wouldn’t show. Read the solution from support here. I don’t know if it has been solved in the meanwhile, if not this is your solution.

TLDR

Always include a form and update method in your widget class.