Skip to content

Instantly share code, notes, and snippets.

@BruceMcKinnon
Created August 6, 2024 05:51
Show Gist options
  • Save BruceMcKinnon/75cce605b36314c191a6b0a46a6216ee to your computer and use it in GitHub Desktop.
Save BruceMcKinnon/75cce605b36314c191a6b0a46a6216ee to your computer and use it in GitHub Desktop.
Support the serving of iframe content from a specific page
//
// Wordpress - Support for iframes being called for a specific page. Add this to functions.php
// In this case, the URL $allowed_url will be allowed to pull the contents of the 'my-embed' page
//
add_action( 'send_headers', 'add_header_xframe', 99 );
function add_header_xframe() {
if ( is_page('my-embed') ) {
$allowed_url = 'http://test.local';
header( 'Content-Security-Policy: frame-ancestors '.$allowed_url );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment