Created
May 20, 2016 12:17
-
-
Save mafsdisseny/f17fd62a3629098fe230c7e54c1ba444 to your computer and use it in GitHub Desktop.
Función para imprimir el formulario adecuado dependiendo del idioma. Usa CF7 y Polylang. Requiere crear los formularios siguiendo unas normas de sintaxis.
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 | |
// Esta función permite imprimir el formulario adecuado dependiendo del idioma. | |
// Lo único que hay que tener en cuenta es que cuando creamos el título del formulario | |
// Hay que hacerlo siguiendo esta norma: "nombre del formulario" + " __" + slug del idioma. | |
// Ejemplo: ESP: "formulario __es", CAT: "formulario __ca", ENG: "formulario __en" | |
// En este ejemplo concreto, habría que llamar la función así: | |
// mafs_print_currentlang_form( 'formulario' ); | |
function mafs_print_currentlang_form( $form_name ) { | |
if ( !function_exists('pll_current_language') ) { | |
return; | |
} | |
$form_title = $form_name . ' __' . pll_current_language(); | |
$lang_form_obj = get_page_by_title( $form_title, OBJECT, 'wpcf7_contact_form' ); | |
echo do_shortcode('[contact-form-7 id="' . $lang_form_obj->ID . '" title="' . $form_title . '"]'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment