Home / social / Create tiny URLs automatically
  • How to Create tiny URLs automatically

    no thumbnail sorry: Create tiny URLs automatically

    Add the first section of code into your functions.php. Adding the second section of code into your single.php template file will automatically create and display the tiny url.

    ( click code to copy )

    wordpress snippet : PHP - Insert into functions.php

    <>
    function getTinyUrl($url) {
        $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
        return $tinyurl;
    }
    
    ( click code to copy )

    wordpress snippet : PHP - Insert into single.php

    <>
    <?php
    $turl = getTinyUrl(get_permalink($post->ID));
    echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>'
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    get_permalink,