BLOG
2021年1月22日
2021年8月23日
使用しているテーマのディレクトリの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”>