the_header_video_url()


WordPressのthe_header_video_url()関数は、ヘッダーに設定されたビデオのURLを取得するために使用されます。この関数は、カスタマイザーで設定されたヘッダービデオのURLを返します。

構文

the_header_video_url();

この関数は引数を受け取りません。

例1: ヘッダービデオのURLを表示する

ヘッダービデオのURLを表示する基本的な例です。

<?php echo the_header_video_url(); ?>

例2: ヘッダービデオのURLを条件付きで表示する

ヘッダービデオが設定されている場合にのみ、URLを表示します。

<?php if ( get_header_video_url() ) { echo the_header_video_url(); } ?>

例3: ヘッダービデオのURLをリンクとして表示する

ヘッダービデオのURLをリンクとして表示します。

<?php if ( get_header_video_url() ) { echo '<a href="' . the_header_video_url() . '">ヘッダービデオを見る</a>'; } ?>

例4: ヘッダービデオのURLをカスタムフィールドに保存する

ヘッダービデオのURLをカスタムフィールドに保存します。

<?php if ( get_header_video_url() ) { update_post_meta( get_the_ID(), 'header_video_url', the_header_video_url() ); } ?>

例5: ヘッダービデオのURLをショートコードで表示する

ヘッダービデオのURLをショートコードとして表示します。

function display_header_video_url() { return the_header_video_url(); }
add_shortcode('header_video_url', 'display_header_video_url');

例6: ヘッダービデオのURLをJavaScriptで使用する

ヘッダービデオのURLをJavaScriptで使用する例です。

<script>var headerVideoUrl = "<?php echo the_header_video_url(); ?>";</script>

注意点

  • ヘッダービデオが設定されていない場合、この関数は空の文字列を返します。
  • カスタマイザーでヘッダービデオが有効になっていることを確認してください。

関連機能: