• Resolved MorbidEntree

    (@morbidentree)


    I’m trying to implement the shortcode found here. 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("https://" + $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"]))
      return $url;
     else
      return "https://" + $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
    }
    
    add_shortcode('url', 'get_url');
    add_shortcode('parentUrl', 'get_parenturl');

    I’m also using the Frontier theme, if it matters.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to implement a custom shortcode?’ is closed to new replies.