Polylang Borrows WordPress’ “Shortcode” Hand – The Case of Custom Translations in Block Theme

Unlocking the Power of the Polylang Plugin | Part 2

A Girl doing coding 2

Shortcodes and Translation: A WordPress Journey

In WordPress Block Themes (also known as Block Themes or Full Site Editing Themes), the traditional method of inserting PHP code directly into template files (such as functions.php, header.php, etc.) cannot (rather difficult) be used in the same way as in WordPress Classic Themes.

Because, the Block Theme uses a combination of block patterns, templates, and template sections, along with the Site Editor for customization. However, we can still add custom PHP code in a few different ways, one of which is by using “shortcodes”.

Words Preparation: Getting Ready

Let’s set the stage: WordPress Block Themes don’t rely on classic PHP templates, meaning our approach needs to match this more modular system. To create custom translations in Polylang, preparation is key. Before diving into code, it’s helpful to clarify what terms or phrases you’ll need to translate. Jot them down and plan their usage across the site.

Installing the Polylang Plugin

First things first—if Polylang isn’t yet a part of your WordPress toolkit, now’s the time. Head over to your WordPress admin dashboard:

Once installed, we’re ready to dig into custom word registrations.

Coding for Custom Words in functions.php

Here’s where the magic begins. By adding a few lines of code to your Block Theme’s `functions.php`  file, you’ll register custom words and enable them as shortcodes. Let’s get started:

Wordpress Theme's functions.php
WordPress Theme’s functions.php

Create shortcode functions

Add this snippet to your `functions.php`  file to ensure Polylang registers your words properly and converts them into usable shortcodes.

Verifying Registration in Polylang

With the code added, let’s check if our custom words are correctly registered:

Once registered and translated, these words are ready for dynamic usage via shortcodes.

Using Shortcodes in Block Themes

Finally, let’s see how to integrate the shortcodes within a WordPress Block Theme:

The shortcode format like so:

[pll_love key=“See you soon”]

Save your changes, and voila! Your translated text will appear dynamically based on the selected language.

The short URL of the present article is: https://selebes.com/taag
cards
Powered by paypal

Leave a Reply

Your email address will not be published. Required fields are marked *