最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to return site_url() without https:

programmeradmin4浏览0评论

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 it would just say siteurl

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

} );

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 it would just say siteurl

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

} );
Share Improve this question asked Apr 26, 2020 at 10:29 PatrickPatrick 2953 gold badges10 silver badges26 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Try below method

$site_url = site_url();
$url = preg_replace("(^https?://)", "", $site_url );
return $url;
发布评论

评论列表(0)

  1. 暂无评论