Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

ronshe on "Polylang shortcode (like qTranslate) for theme options and text"

$
0
0

Hi,

qTranslate is based on shortcodes to differentiate between the languages.
The only places I found this need in Polylang is in theme options strings.
Right now I need it for Craft theme. There are texts in home page and there is no other way to have them per language without changing the theme.

Anyway, I wrote the shortcode:

// [polylang lang="en"]English[/polylang][polylang lang="sp"]Spanish[/polylang]
function polylang_shortcode($atts, $content = null)
{
	if (empty($content))
		return '';
	extract( shortcode_atts( array('lang' => ''), $atts ) );
	if (empty($lang))
		return "<h3>You must specify 'lang' using shortcode: polylang</h3>";

	return ($lang == pll_current_language()) ? $content : '';
}
add_shortcode('polylang', 'polylang_shortcode');

enjoy,
Ronny

https://wordpress.org/plugins/polylang/


Viewing all articles
Browse latest Browse all 11471

Trending Articles