Last active
October 10, 2023 11:25
-
-
Save zeshanshani/60bdf497bcae87bd3a8b03920cf64fc6 to your computer and use it in GitHub Desktop.
Creates separate Advanced Custom Fields options pages for the specified languages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Don't copy this line if you are inserting in a file that has it already. | |
/** | |
* ACF Options Page | |
* | |
* Instructions: | |
* Add more languages to the array below: $languages | |
* | |
* @author: Zeshan Ahmed <https://zeshanahmed.com/> | |
*/ | |
if ( function_exists( 'acf_add_options_page' ) ) { | |
// Main Theme Settings Page | |
$parent = acf_add_options_page( array( | |
'page_title' => 'Theme General Settings', | |
'menu_title' => 'Theme Settings', | |
'redirect' => 'Theme Settings', | |
) ); | |
// | |
// Global Options | |
// Same options on all languages. e.g., social profiles links | |
// | |
acf_add_options_sub_page( array( | |
'page_title' => 'Global Options', | |
'menu_title' => __('Global Options', 'text-domain'), | |
'menu_slug' => "acf-options", | |
'parent' => $parent['menu_slug'] | |
) ); | |
// | |
// Language Specific Options | |
// Translatable options specific languages. | |
// | |
$languages = array( 'it', 'en' ); | |
foreach ( $languages as $lang ) { | |
acf_add_options_sub_page( array( | |
'page_title' => 'Options (' . strtoupper( $lang ) . ')', | |
'menu_title' => __('Options (' . strtoupper( $lang ) . ')', 'text-domain'), | |
'menu_slug' => "options-${lang}", | |
'post_id' => $lang, | |
'parent' => $parent['menu_slug'] | |
) ); | |
} | |
} |
Some ways to replace the:
$languages = array( 'it', 'en' );
to automatically add the WPML languages?
@scesini According to the Polylang documentation, you can use the pll_the_languages
function to retrieve all available languages.
Replace:
$languages = array( 'it', 'en' );
with:
$polylang_languages = pll_the_languages(['raw' => 1]);
$languages = array_column($polylang_languages, 'slug');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you don’t want to manually add or remove languages.
Just replace -
$languages = array( 'it', 'en' );
39 string with -This is relevant for Polylang plugin