• Resolved the_ausswe

    (@the_ausswe)


    In WP posts I have added a custom field named ‘googledriveurl’ in which a URL to Google Drive can be added. The WP installation is only on localhost at this stage and uses Polylang to handle two different languages (Swedish and English).

    I have tried to create a shortcode in functions.php to return an a href link with the custom field included, along with some text in respective language and so far I have tried:

    function googlesheetpdf_shortcode() {
        if (pll_current_language() == 'sv_SE') {
        echo '<a href="CUSTOMFIELD/view#gid=0">Spara som PDF</a>';
         } else echo '<a href="CUSTOMFIELD/view#gid=146971">Save as PDF</a>';
         }
    add_shortcode('googlesheetpdf', 'googlesheetpdf_shortcode');

    I have searched around and tried a number of ways that I’ve come across but I’m stuck and confused – so I thought I’d ask and see if anyone could help.

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter the_ausswe

    (@the_ausswe)

    So it looks like I managed to get it sorted! In case someone else is trying the same here is the code I ended up with:

    function googlesheetpdf_shortcode() {
        $googleurl = get_post_meta(get_the_ID(),'do_googlesheet', array( 'output_as' => 'text' ));
        if (pll_current_language() == 'sv') {
        return> '<a href="' . $googleurl . '/view#gid=0">Spara som PDF</a>';
         } else return '<a href="' . $googleurl . '/view#gid=146971">Save as PDF</a>';
         }
    add_shortcode('googlesheetpdf', 'googlesheetpdf_shortcode');
    • This reply was modified 4 years, 7 months ago by the_ausswe.
Viewing 1 replies (of 1 total)
  • The topic ‘Call custom field in functions.php’ is closed to new replies.