概要説明
iframe,embed,objectタグからの埋め込みを禁止させたい時のカスタマイズ。埋め込んだコンテンツを自コンテンツのように表示させ、ボタンなどは任意の内容を実行させる行為を防ぎやすくなります。
.htaccessでiframe制御する場合
.htaccess
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<ifModule mod_headers.c>
Header set X-Frame-Options DENY
Header set Content-Security-Policy "frame-ancestors 'none';"
</ifModule>
<ifModule mod_headers.c>
Header set X-Frame-Options DENY
Header set Content-Security-Policy "frame-ancestors 'none';"
</ifModule>
<ifModule mod_headers.c> Header set X-Frame-Options DENY Header set Content-Security-Policy "frame-ancestors 'none';" </ifModule>
functions.phpでiframe制御する場合
functions.php
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*----------------------------------------------------
iframe埋め込みの制御
----------------------------------------------------*/
if ( !function_exists( 'deny_iframe_http_headers' ) ){
function deny_iframe_http_headers() {
header('X-FRAME-OPTIONS: DENY'); // 禁止
//header('X-FRAME-OPTIONS: SAMEORIGIN'); // 自サイトのみ許可
}
add_action( 'send_headers', 'deny_iframe_http_headers' );
}
/*----------------------------------------------------
iframe埋め込みの制御
----------------------------------------------------*/
if ( !function_exists( 'deny_iframe_http_headers' ) ){
function deny_iframe_http_headers() {
header('X-FRAME-OPTIONS: DENY'); // 禁止
//header('X-FRAME-OPTIONS: SAMEORIGIN'); // 自サイトのみ許可
}
add_action( 'send_headers', 'deny_iframe_http_headers' );
}
/*---------------------------------------------------- iframe埋め込みの制御 ----------------------------------------------------*/ if ( !function_exists( 'deny_iframe_http_headers' ) ){ function deny_iframe_http_headers() { header('X-FRAME-OPTIONS: DENY'); // 禁止 //header('X-FRAME-OPTIONS: SAMEORIGIN'); // 自サイトのみ許可 } add_action( 'send_headers', 'deny_iframe_http_headers' ); }