この記事は最後に更新してから1年以上経過しています。
説明
投稿記事の中で画像パーツを使いたいときがある。画像パーツの配置場所は、/imgディレクトリのようなテーマ外の場合と、/wp-content/themes/mytheme/imagesディレクトリのようなテーマ内の場合があり、今回は後者のケース。ショートコードを使って投稿記事の画像ファイルのURLを記述する方法を紹介したい。 通常、投稿記事にテーマ内の画像ファイルを入れる場合、<img src="/wp-content/themes/mytheme/images/logo.gif" />
<img src="http://localhost/wp-content/themes/mytheme/images/logo.gif" />
<img src="[tp /]/images/logo.gif" />
<img src="[tp]/images/logo.gif[/tp]" />
add_shortcode( 'tp', 'shortcode_tp' );
function shortcode_tp( $atts, $content = '' ) {
return get_template_directory_uri().$content;
}
最終更新 : 2018年05月27日 10:53
関連
お勧め
count_users(2019年3月1日 更新)
array count_users( [ string $strategy = 'time' [, int $site_id = null ] ] )
役割別のユーザ数を取得する。
wp_embed_defaults(2011年12月1日 更新)
array wp_embed_defaults( )
投稿記事中に埋め込む動画などのサイズを取得する。
the_posts_navigation(2019年9月25日 更新)
void the_posts_navigation( [ array $args = array() ] )
アーカイブページ向けのナビゲーションを表示する。
show_admin_bar(2012年1月5日 更新)
void show_admin_bar( bool $show )
ツールバー(admin bar)を強制的に表示/非表示する。
wp_spam_comment(2013年9月6日 更新)
bool wp_spam_comment( $comment_id )
コメントをスパムにする。