How to remove “http://” When Echoing URL?

I’m seeking to echo the domain name (url) without the ‘http://’ (or ‘https://’).

I’ve created the following:

<?php $surl = bloginfo('url'); $findh = array( 'http://' ); $replace=""; $outputh = str_replace( $findh, $replace, $surl ); echo $outputh; ?>

also another one (of many) I tried:

<?php $surl = bloginfo('url'); echo str_replace('http://', '', $surl); ?>

Seems like a simple task, but output still includes the ‘http://’ when the domain is echo’d. Reviewed other posts here and other sites to no avail. Perhaps something within WordPress base files is interfering, not sure on this one.

Thanks in advance for any feedback!

4 Answers
4

bloginfo echos its result, this is why your attempt to “get the value” and manipulate it results in nothing, as no value is actually being returned. If you want to get the relevant value you should use get_bloginfo instead

Leave a Comment