Support » Plugin: Options Framework » Polylang compatibility

  • Resolved RavanH



    I’m working with a payed theme (NonProfit Theme by Organic Themes) that uses the Options Framework to define where to show pages and posts from which categories on the front page.

    It turns out this is completely incompatible with the multi-lingual plugin Polylang as the selected pages and categories are not switched to their respective language counterparts when a visitor switches the site language…

    Is there any way to achieve this?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi RavanH,

    Hopefully you will find an option (which stores these pages and categories) to filter. Then you can use the functions, ‘pll_get_post’ to get the id of the translated page and ‘pll_get_term’ to get the id of the translated category.

    Sadly, there is no such possibility… Have to go with qTranslate as alternative. It does not have my preference but at least it works without completely rebuilding the theme 😉

    Anyway, thanks for the support!

    I am surprised that there is no solution. What is the code to get selected pages and categories?

    You are right, there probably is a solution. I just figured it would be too much work (for a small clients site) to comb though all theme files and adapt them with polylang specific function calls, also because that would render the theme useless when Polylang is (accidentally or not) switched off one day.

    For example, in the theme’s home.php itself I find a lot of loops like this:

    <?php $recent = new WP_Query('page_id='.of_get_option('select_pages_mid_1')); while($recent->have_posts()) : $recent->the_post();?>
    <?php endwhile; ?>

    where the parameter 'page_id='.of_get_option('select_pages_mid_1') changes each time. The function of_get_option() is part of the Options Framework plugin.

    I did not go through that plugin to find out if there is a nice filter hook available that would allows one or a few filters in functions.php. Again, too much work for one small clients site 😉

    However, it appears there are more themes out there that use the Options Framework so it might be useful to find out if there would be much work involved in getting Polylang and that plugin compatible out of the box somehow. But I fear it is too unpredictable. Impossible to say what options are used for what kind of data (posts,taxonomy,plain texts or whatever) so no way of knowing which filter function to apply without knowing where in the theme it is used…

    Here is the ‘of_get_option’ function.

    if ( ! function_exists( 'of_get_option' ) ) {
    	function of_get_option( $name, $default = false ) {
    		$config = get_option( 'optionsframework' );
    		if ( ! isset( $config['id'] ) ) {
    			return $default;
    		$options = get_option( $config['id'] );
    		if ( isset( $options[$name] ) ) {
    			return $options[$name];
    		return $default;

    It looks like you can write your own function outside the plugin, but I propose not to use this possibility, as it is not robust (you will have to rely on plugin name to be sure that your own function is loaded before this one…)

    So it is better to take profit of the standard WordPress option filter.

    $config = get_option( 'optionsframework' );
    if (isset( $config['id'] ))
    	add_filter('option_' . $config['id'], 'my_option_filter');
    function my_option_filter($options) {
    	// use pll_get_post to translate posts and pages
    	// use pll_get_term to translate categories and post tags
    	$options['select_pages_mid_1'] = pll_get_post($options['select_pages_mid_1']); // I expect this option contains a page id
    	return $options;

    I understand that it is to late for you. But hopefully, it will help someone else in the future (NB: I did not test, but it should work).

    Thanks Chouby, your dedication is remarkable! 🙂

    Hi, I am also using the non-profit theme. I don’t have any experience with creating websites. I can’t get the menu to switch when the new language is selected. The documentation is saying go to the languages page to set menu by going to the theme locations on the language page but the menu page there is blank.
    Where do I put in all of the information you have stated above?Where is the function php page, etc. I really need some help. Thanks

    Ah yes, that is another issue with the non-profit theme and Polylang. The above code suggestion by Chouby will not address that issue, I’m afraid.

    Do you mean that the Settings->languages->menus tab exists but is empty?
    Could you explain step by step what you did to create your menus?

    @yolonda1w, the issue with the menu seems to be caused by something else. You might want to contact the theme developer about it. Make sure you try without Polylang first. Once you’ve got the menu working, the rest is not too difficult…

    After a long hard wrestle with qTranslate and finaly giving up after it completely broke with the upgrade to 3.5, I decided to put in the work to fix the themes home.php for Polylang compatibility.

    I’m glad I did and it was easier than expected 🙂

    Editing the home.php file, I added a global $polylang; at the top (did I need to?) and then adapted the rest using pll_get_term and pll_get_post…

    For example, the part of the featured slider code that was:

    <?php $recent = new WP_Query("cat=" .of_get_option('select_categories_slider')); while($recent->have_posts()) : $recent->the_post();?>


    if (isset($polylang))
        $thiscat = pll_get_term(of_get_option('select_categories_slider'));
        $thiscat = of_get_option('select_categories_slider');
    $recent = new WP_Query("cat=" .$thiscat); while($recent->have_posts()) : $recent->the_post();?>

    (notice pll_get_term here)

    Or the part of the left featured page code that was:

    <?php $recent = new WP_Query('page_id='.of_get_option('select_pages_mid_1')); while($recent->have_posts()) : $recent->the_post();?>


    if (isset($polylang))
    	$midpage = pll_get_post(of_get_option('select_pages_mid_1'));
    	$midpage = of_get_option('select_pages_mid_1');
    $recent = new WP_Query('page_id='.$midpage); while($recent->have_posts()) : $recent->the_post();?>

    (notice pll_get_post here)

    about the need for ‘global $polylang”: In some way you are obliged to test for the presence of Polylang, so either the way you are doing or directly by testing the Polylang function ‘pll_get_post’, this should be pretty much the same.

    No, I meant: do I need to define/call $polylang as global in the theme template or would it be available without that…

    Oh yes. If you use it explicitely, I believe that you need to define it as global (the variable is created inside a class).

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Polylang compatibility’ is closed to new replies.