Forum Replies Created

Viewing 15 replies - 46 through 60 (of 85 total)
  • Hi
    Yes it supports Advanced Custom Fields, I use it on my website.

    Have you looked at this document? https://polylang.pro/doc/function-reference/

    Have you registered the the strings in functions.php file first?

    It should look like this:

    add_action('init', function() {
        if (function_exists('pll_register_string')) {
            pll_register_string('Your String', 'Your String');
     }
    });

    Then open String Translations in WordPress Dashboard and you should see your new registered strings. You then have to add the translation for ‘Your String’.

    You then need to add the custom fields to your template file in order to get the values.

    I hope this helps.

    Morris

    Hi
    pll_e
    Echoes a translated string previously registered with pll_register_string, I have just tried this on my website and it does not work. I think it is used just to output the translated string without using ‘echo’.

    pll__
    translates a string previously registered with pll_register_string, this is the way I have done it and it works.

    The code should look like this below and without <ul> on the end as you’ve got it:

    <?php 
    $textlable = pll__('varietes');
    echo '<div class="related"><h4 class="related-portfolio">' . $textlabel . '</h4>';
    ?>

    I put that as my first answer but used <?php $allrightsreserved = pll__('All Rights Reserved'); ?> as an example as I use it on my website.

    Just try it.

    Morris

    Hi
    I have used the following:

    <?php $allrightsreserved = pll__('All Rights Reserved'); ?>

    and then inserted the variable into the copyright bit at the bottom of the page.

    <?php echo '&copy;&nbsp;' . date('Y') . ', ' . $allrightsreserved; ?>

    I hope that helps.

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    Just found out that each page or document just needs the language attribute set as <html lang="en"> or <html lang="your language"> but if there’s mixed languages on the same page then each different language other than the page’s language has to have for example <p lang="cy"> set.

    This looked like a nightmare, especially if every page content in a different language needed doing.

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    I modified the code so that I could pass an array of languages (en for English and cy for Welsh) through a loop as I thought it would add the English – Welsh titles and Welsh – English titles but it still only adds the Welsh – English.

    /** Add Post State to Page Title */
    add_filter( 'display_post_states', 'my_post_states', 10, 2 );
    function my_post_states( $post_states, $post ) {
        $pages = get_pages();
        $languagesArray = ["en", "cy"];
        foreach ($languagesArray as $language) {
            if (pll_get_post( $post->ID, $language )) {
                foreach ($pages as $page) {
                    $tr_id = pll_get_post( $post->ID, $language );
                    if($tr_id) {
                        if ( $page->post_title ) {
                            $post_states['translated_title'] = get_the_title( $tr_id );
                        }
                        return $post_states;
                    }
                }
            }
        }
    }
    /** end **/

    If the page exists or if you create a new page then obviously the translated page does not exist. If you now create the translated page then the code works but on Welsh -English pages, for some reason it won’t add the English – Welsh version.

    I am not a PHP programmer so I don’t know where I have gone wrong, anyone got any ideas that can fix this code?

    Cheers

    Morris

    • This reply was modified 4 years, 6 months ago by morris373.
    Thread Starter morris373

    (@morris373)

    Hi Chouby
    I am not sure how that fits in with my code or do I just replace it all.

    The code so far:

    /** Add Post State to Page Title */
    add_filter( 'display_post_states', 'my_post_states', 10, 2 );
    function my_post_states( $post_states, $post ) {
        $pages = get_pages();
        
        if (pll_get_post( $post->ID, 'en' )) {
            foreach ($pages as $page) {
                $tr_id = pll_get_post( $post->ID, 'en' );
                if($tr_id) {
                    if ( $page->post_title ) {
                        $post_states['translated_title'] = get_the_title( $tr_id );
                    }
                return $post_states;
                }
            }
        }
    }
    /** end **/

    Languages to be used English and Welsh.

    This code works but not properly. it does add the English verion to the Welsh page title but the English version, the English page title is = to the english page title and not the Welsh page title.

    How can I modify this code above so that I get in Pages => All Pages:

    English Title – Welsh Title

    Welsh Title – English Title

    Thanks

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    I finally solved my problem by looking for solutions on the Internet and using a Custom Field. It works on Pages and Posts.

    My final code is:

    /** Add Post State to Page Title */
    add_filter( 'display_post_states', 'my_post_states', 10, 2 );
    function my_post_states( $post_states, $post ) {
        $pages = get_pages(); 
        foreach ($pages as $page) {
            if (!is_front_page()) {
                if(get_field('translated_title')) {
                    if ( $page->post_title ) {
                        $post_states['translated_title'] = get_field('translated_title');
                    }
                return $post_states;
                }
            }
       }
    }
    

    I hope others will find it useful especial if building a Bilingual WordPress Website.

    Cheers

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    Sorry to mention any plugins but I started today not knowing how to describe what I wanted to do and I just used them as examples of how they did what I wanted to achieve.

    To modify the code now is probably a PHP question now as I found what creates the Post State i.e. ‘display_post_states’

    Hopefully this is useful for other WordPress users.

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    Just found what I was looking for, so now I have this:

    add_filter( 'display_post_states', 'my_post_states', 10, 2 );
    function my_post_states( $post_states, $post ) {
        if ( 13 === $post->ID ) {
            //$post_states['cysylltwch'] = 'Cysylltwch';
        }
    
        if ( 'Contact Us' === $post->post_title ) {
            $post_states['cysylltwch'] = 'Cysylltwch';
        }
    
        if ( About === $post->post_title ) {
            $post_states['am'] = 'Am';
        }
    
        return $post_states;
    }

    Now, I need to do this to all the pages. Could there be an easier way to do this maybe via 2 arrays and a loop?

    Or maybe a plugin that already exists…I could then create a page in one language and then add the translated word, save the page and after that the post state is automatically added.

    That would be far quicker, it would just be like the Slug field or a Custom Field.

    Cheers

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    I found this code but I would rather use the actual page title so how can this code be changed from the ID?

    The language below is English and Welsh.
    Post ID – 13, is Contact Us so that gives me Contact Us – Cysylltwch and
    Post ID – 11 is About so that gives me About – Am

    add_filter( 'display_post_states', 'my_post_states', 10, 2 );
    function my_post_states( $post_states, $post ) {
        if ( 13 === $post->ID ) {
            $post_states['cysylltwch'] = 'Cysylltwch';
        }
    
        if ( 11 === $post->ID ) {
            $post_states['am'] = 'Am';
        }
    
        return $post_states;
    }

    Cheers

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    Just looking at the code in Polylang and it refers to those pages as Post States.

    So Setting a page called Home as the Front page, in All Pages it shows:

    Home – Front Page and Blog – Posts page

    So how can I use the same Post State to add similar to the Contact page for example but in a different language so when I view all the pages I will be able to identify the Contact’s page in a different language with the english version next to it?

    Woocommerce does the same to there pages for like Cart, Shop page, Checkout page and My Account page.

    And it uses this code but can it be used for my other pages with some modification:

    add_filter( 'display_post_states', 'add_display_post_states', 10, 2 );

    Thanks

    Morris

    • This reply was modified 4 years, 6 months ago by morris373.
    Thread Starter morris373

    (@morris373)

    Hi Dan
    I quickly tried it on another website and it worked with that piece of code added to wp-config.php.

    Again it didn’t work at first so maybe clear the cache and refresh the page but I did open a couple of Pages first.

    Now working, I will use the same technique on another website.

    Thanks

    Morris

    Thread Starter morris373

    (@morris373)

    Hi Dan
    I tried all that before what you mentioned, but I found this Blog and I followed Option 5 on => https://blog.hubspot.com/website/wordpress-visual-editor-not-working

    At first it didn’t work but I opened a page up and the TinyMCE was there but that wasn’t the issue as it’s always worked.

    After opening a page, I opened Pins again and the Visual Editor came up in Advanced and Simple Mode. I couldn’t get Simple Mode to work either and now it is.

    I see if my other 2 websites will work when I add the same line into wp-config.

    I will let you know later if it works or not.

    Thanks

    Morris

    • This reply was modified 4 years, 6 months ago by morris373. Reason: Spelling
    Thread Starter morris373

    (@morris373)

    Hi Cristain
    I have added the alt text, caption and title but I want to know the PHP code to add it to homepage’s template file.

    Also I can’t get your video to work.

    Thanks

    Morris

    Thread Starter morris373

    (@morris373)

    Hi
    I have checked the folder permissions for TinyMCE and they are set to 755.

    I have changed the Theme, still not working.

    I have deactivated all Plugins except Bing Map Pro and still not working.

    I have saved Permalinks twice, still not working.

    PHP is set to Version 7.3

    WordPress has been updated to version 5.5

    Tried adding a new Pin and didn’t work.

    I have tried everything I know and I still can’t get it to work.

    For now as I only had 6 pins, I added the infoformation to the Infobox via the database and for now it is working. Not ideal but jobs done.

    Thanks

    Morris

    • This reply was modified 4 years, 6 months ago by morris373.
Viewing 15 replies - 46 through 60 (of 85 total)