Title: How to implement a custom shortcode?
Last modified: August 24, 2016

---

# How to implement a custom shortcode?

 *  Resolved [MorbidEntree](https://wordpress.org/support/users/morbidentree/)
 * (@morbidentree)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-implement-a-custom-shortcode/)
 * I’m trying to implement the shortcode found [here](https://gist.github.com/jongalloway/d3d797546e8d6f608a75).
   But when I put it into the functions.php of my theme it shows an error.
 * This is the coding for the shortcode:
 *     ```
       function get_url($atts) {
        $pageURL = 'http';
        if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
         $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
         $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $pageURL;
       }
   
       function get_parenturl($atts) {
        $url = rtrim(get_url($atts),"/");
        $url = substr($url, 0, strrpos($url,"/"));
        if(strlen($url)>strlen("http://" + $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"]))
         return $url;
        else
         return "http://" + $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
       }
   
       add_shortcode('url', 'get_url');
       add_shortcode('parentUrl', 'get_parenturl');
       ```
   
 * I’m also using the [Frontier theme](https://wordpress.org/themes/frontier/), 
   if it matters.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Rajesh Soni](https://wordpress.org/support/users/rajeshsoni/)
 * (@rajeshsoni)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-implement-a-custom-shortcode/#post-5969577)
 * > …when I put it into the functions.php of my theme it shows an error.
 * What error on which page (URL) ?
 *  Thread Starter [MorbidEntree](https://wordpress.org/support/users/morbidentree/)
 * (@morbidentree)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-implement-a-custom-shortcode/#post-5969594)
 * Hm, never mind. I must have just put the shortcode code in a bad place. It works
   now.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to implement a custom shortcode?’ is closed to new replies.

## Tags

 * [shotcode](https://wordpress.org/support/topic-tag/shotcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [MorbidEntree](https://wordpress.org/support/users/morbidentree/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-implement-a-custom-shortcode/#post-5969594)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
