三鷹市・武蔵野市(吉祥寺)のホームページ制作会社です。三鷹市・武蔵野市(吉祥寺)のホームページ制作なら私たちにお任せください。

BLOG

使用しているテーマのディレクトリのURIの表示について

使用しているテーマのディレクトリのURIを表示するには、get_template_directory_uriを使用します。

子テーマを使用している場合は、親テーマのディレクトリのURIを返します。

子テーマのディレクトリのURIを表示すには、get_stylesheet_directory_uriを使用してください。

主な使用例

  • <script src=”<?php echo get_template_directory_uri(); ?>/js/example.js”></script>
  • <link href=”<?php echo get_template_directory_uri(); ?>/css/style.css” rel=”stylesheet”>
  • <img src=”<?php echo get_template_directory_uri(); ?>/images/example.jpg” alt=”example”>

上記はブラウザで表示されると以下になります。

  • <script src=”https://example.com/wp-content/themes/example/js/example.js”></script>
  • <link href=”https://example.com/wp-content/themes/example/css/style.css” rel=”stylesheet”>
  • <img src=”https://example.com/wp-content/themes/example/images/example.jpg” alt=”example”>