Support » Plugins and Hacks » Need to get the permalink outside the loop (functions.php)

  • Hi There,

    I need to get the permalink outside of my function.php file, which will be executed when the browser loads. The following is the script that I have been working on…

    file –> functions.php
    $sharepermalink = ‘<?php the_permalink() ?>’;
    /* I need the permalink only when the single.php template loads and grabs the permalink then to extract the json string as mentioned below */

    $fbsharelink = ‘http://www.facebook.com/sharer.php?u=’;

    $fbcount = @json_decode(file_get_contents(‘https://graph.facebook.com/’.$sharepermalink));
    $fbsharecounts = number_format($fbcount->shares);

    file –> single.php
    <?=$fbsharecounts;?>
    /* print the value stored in the variable fbsharelink */

    Goal : When ever my single post page loads the function.php has pull the permalink and process the remaining codes and stores the final answer into a variable $fbsharecounts

    Kindly help me.

  • The topic ‘Need to get the permalink outside the loop (functions.php)’ is closed to new replies.