My theme (Novo Theme) lets you create pages as footers.
I created a footer in German and one in English and linked them in polylang.
In Polylang Settings > Custom post types and Taxonomies I checked everything including "Footers (yprm_footer_builder)"
The footer being displayed is always the one selected in Appearance -> Customize.
I tried adding
<?php
// Get the current language code
$current_language = pll_current_language();
// Check if the current language is English
if ($current_language == 'en') {
// Display the English footer
get_template_part('footer-en');
} elseif ($current_language == 'fr') {
// Display the French footer
get_template_part('footer-fr');
} else {
// Display the default footer
get_template_part('footer');
}
?>
to the page template as suggested by Google AI.
I also tried adding
function switch_footer_language() {
if(pll_current_language=='th') {
get_footer('footer_th.php');
} elseif(pll_current_language=='en') {
get_footer('footer_en.php');
}
}
as suggested at Switch footer for different languages on Wordpress website using Polylang plugin and Footer in multiple languages free WordPress
I couldn't even get it to echo "DE" or "EN" depending on language, let alone to change the footer.
As far as I understand from posting on wordpress stackexchange at https://wordpress.stackexchange.com/questions/428859/changing-footer-according-to-language (question closed because outside their scope), I don't need to load footer_en or footer_de but a page.
Different themes (like Avada Theme) apparently work by selecting the language as described here: Footer using Avada Theme in Wordpress and the Polylang Plug-In but not Novo
I also contacted Envato Theme Support but got told customisation is beyond their scope. I have some programming skills and some worpress knowledge but not enough to take a good guess on where to start looking which support also didn't want to tell me.
So, my questions are:
How do I find the location where the footer page gets picked?
Can I change it according to Polylang-Language using php? Would the ybove code be correct for querying the langauage set by polylang?
Would I (probably) have to change each template the theme provides or is there a more central location?
Clarification: the theme loads a page's content as a footer, not the whole page, which is a big difference. We'll do the same.
First, you need the IDs of the pages with the content you want to load. You can easily find them in the URL while editing the page in question. We use "123" for English and "124" for German as placeholders here.
The following code does the loading and you have a couple of options where to execute it (see below).
<?php
$pages = [
"en" => 123,
"de" => 124,
];
$current_language = pll_current_language();
if (isset($pages[$current_language])) {
$id_page = $pages[$current_language];
$page = get_post($id_page);
if ($page) {
global $post;
$post = $page; // Set up global post
setup_postdata($post); // Prepares post data for filters like the_content
echo apply_filters("the_content", $post->post_content);
wp_reset_postdata(); // Restore original global $post
}
}
?>
User @mmm provided the base for this, AI did the missing bits.
Option 1 (my pick): I use the free version of the plugin "WP Code" to use code snippets anyway (mostly for text that appears on multiple pages, so if there are changes, they only need to be edited in one place). In WP Code I made use of the "php snippet" with the following options:
Insert Method: Auto Insert
Location: Global/Site Wide Footer
Device Type: Any device type
Option 2: create a child theme and add the php to footer.php. I had problems with the menus not showing after creating the child theme, so after some experimentation, I abandoned this route.
Option 3: Execute the php within the footer page the theme lets you load. I believe you'll need a plugin to execute php from within a page. I did not try this.