• 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://www.ads-software.com/plugins/polylang/

Viewing 3 replies - 16 through 18 (of 18 total)
  • Wow I don’t know how but I managed to do it with the strings ?? The custom field didnt accept php code so I made some changes to index.php and the magic happened. For those who are wondering how to use strings here how I managed to do it:

    in functions.php I wrote just after the opening <?php tag: pll_register_string(‘intro_content’,’Text here’,’SPA’);

    It doesn’t matter what you will type in the brackets actually. It is used just to find it in the String translation panel in Polylang options.
    intro_content is the name, Text here is the string to be pulled out and SPA is my theme.

    The string should be on the Polylang settings page now. Go and translate it for any added language.

    Then in the custom field which you want to be translated just type <?php pll_e('Text here'); ?> and it will pull out the translation you made in the popylang settings page.

    For my case the custom field don’t accept php codes so I went to index.php ( where the custom field appear;) and replaced the php code there with the above one.

    And this is my noob guide ?? I know it is funny for the developers who understand perfectly the plugin’s guide but after all not everyone who visits this forum is a professionalist.

    Hello,

    As I am working with polylang on a website that uses a very specific theme, I’m very glad to find your short code trick, that really helped me a lot.

    Thank you ??

    Thread Starter Ronny Sherer

    (@ronshe)

    Thanks for the acknowledgement numerosix. I am glad you found it helpful.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Polylang shortcode (like qTranslate) for theme options and text’ is closed to new replies.