I am retrieving the site URL and creating a shortcode to display it. However when i return the site URL as expected it contains the full string including https://

How can i return the site url without the https:// part? So instead of https://siteurl.com it would just say siteurl.com

add_action( 'init', function() {
    add_shortcode( 'site_url', function( $atts = null, $content = null ) {
        return site_url();
    } );

} );

Try below method

$site_url = site_url();
$url = preg_replace("(^https?://)", "", $site_url );
return $url;
  • Thanks mate! That makes perfect sense – Patrick Apr 26 '20 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.