有時候寫php時會用到取得該篇post的網址或者根目錄的網址功能,這時候get_site_url()就可以派上用場。
函示說明:
get_site_url( int $blog_id = null, string $path = '', string $scheme = null )
另外,也有另一組函式get_home_url( )可以使用,用法相同:
get_home_url( int $blog_id = null, string $path = '', string|null $scheme = null )
作法如下:
- 取得網站的網址:
<?php $url = get_site_url();
<?php $url = get_home_url();
- 取得網址加上次級目錄:
<?php $url = get_site_url(null, '/wp-content/themes/', 'https');
- 取得post id 為 143的網址:
<?php $url = get_site_url('143');
Recent Comments