Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Astra Portfolio: iFrame Compatibility JS & CSS files include though JS.
<?php
/**
* Astra Portfolio iFrame Compatibility
*
* @todo Change the `http://example.com/` with your own domain where the portfolio showing the portfolios.
*
* @since 1.0.0
*/
if( ! function_exists( 'astra_portfolio_iframe_compatibility' ) ) :
function astra_portfolio_iframe_compatibility() {
?>
<script type="text/javascript">
// Set the Portfolio Site URL.
astraPortfolioiFrameCompatibility( 'http://example.com/' );
/**
* Astra Portfolio Compatibility
*
* Add the Astra Portfolio Compatibility CSS & JS files from the plugin.
*
* @since 1.0.0
*
* @param string siteUrl Site URL
* @return void
*/
function astraPortfolioiFrameCompatibility( siteUrl ) {
var isInIFrame = ( window.self !== window.top ) ? true : false;
if( isInIFrame ) {
// Add script.
var script = document.createElement('script');
script.setAttribute('id', 'astra-portfolio-compatibility-js');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', siteUrl + 'wp-content/plugins/astra-portfolio/assets/js/compatibility.js');
document.head.appendChild(script);
// Add style.
var style = document.createElement('link');
style.setAttribute('id', 'astra-portfolio-compatibility-css');
style.setAttribute('rel', 'stylesheet');
style.setAttribute('type', 'text/css');
style.setAttribute('media', 'all');
style.setAttribute('href', siteUrl + 'wp-content/plugins/astra-portfolio/assets/css/compatibility.css');
document.head.appendChild(style);
}
}
</script>
<?php
}
add_action( 'wp_head', 'astra_portfolio_iframe_compatibility' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.