WordPress.org

Ready to get started?Download WordPress

Forums

Need to get the permalink outside the loop (functions.php) (1 post)

  1. bensonshaji
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic