site_url

Sponsored Link

site_urlテンプレートタグは、適切なプロトコルである現在のサイト(ここでは、WordPressのコアファイル)のためにサイトURLを取得し、’https’がis_ssl()と’http’の場合、上書きします。

WordPressネットワークのセットアップの場合は、network_site_url()を代わりに使用してください。

Sponsored Link

The site_url template tag retrieves the site url for the current site (where the WordPress core files) with the appropriate protocol, ‘https’ if is_ssl() and ‘http’ otherwise. If scheme is ‘http’ or ‘https’, is_ssl() is overridden.

In case of WordPress Network setup, use network_site_url() instead.

site_urlのテンプレートタグ使用方法

<?php site_url( $path, $scheme ); ?>

デフォルトの使い方

<? php echo site_url(); ?>

site_urlのパラメーター

$path

(string) (optional) パスは、サイトのURLに付加されます。
デフォルト:なし

(string) (optional) Path to be appended to the site url.
Default: None

$scheme

(string) (optional) URLのプロトコルのためのコンテキストが返されます。 $schemeを設定すると、デフォルトのコンテキストを上書きされます。指定できる値は、’http’,’https’, ‘login’, ‘login_post’, または ‘admin’です。
デフォルト:null

(string) (optional) Context for the protocol for the url returned. Setting $scheme will override the default context. Allowed values are ‘http’,’https’, ‘login’, ‘login_post’, or ‘admin’.
Default: null

返り値

(string) オプションのパスが付加されているサイトURLリンクです。

(string)
Site url link with optional path appended.

$url = site_url();
echo $url;

出力: http://www.example.com か http://www.example.com/wordpress

(最後のスラッシュがないことに注意)

(Note the lack of a trailing slash)

$url = site_url('/secrets/', 'https');
echo $url;

出力: https://www.example.com/secrets/ か https://www.example.com/wordpress/secrets/

注釈

  • get_site_url()を使用します。
  • ‘siteurl’ オプションを使用します。

変更ログ

Since: 2.6.0

ソースファイル

site_url()は、wp-includes/link-template.php内に位置しています。

site_url() is located in wp-includes/link-template.php.

関連テンプレートタグ

home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com OR http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin/
includes_url() Includes directory URL http://www.example.com/wp-includes/
content_url() Content directory URL http://www.example.com/wp-content/
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins/
Sponsored Link