Skip to content

Instantly share code, notes, and snippets.

@Jany-M
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jany-M/06b0575b202e643e2469 to your computer and use it in GitHub Desktop.
Save Jany-M/06b0575b202e643e2469 to your computer and use it in GitHub Desktop.
[WordPress] Print Friendly Plugin Template Add-On - Add custom classes inside nested iFrames for customization based on Post Type
<?php if(is_singular('slug-of-post-type')) :
global $post;
$p_type = get_post_type(get_the_ID());
?>
<script type="text/javascript">
jQuery(document).ready(function() {
$( ".printfriendly a" ).click(function() {
$("#pf-core").load(function() {
setTimeout( function () {
//console.log( $('#pf-core').contents().find('iframe').contents().find('#pf-print-area') );
$('#pf-core').contents().find('iframe').contents().find('#pf-print-area').addClass("pf-<?php echo $p_type; ?>");
}, 1000 );
// You can lower the milliseconds (1000 by default), if you see a big delay in the way the style is applied, however I dont advise to keep it too low, since the second iFrame will take *a little* time to load anyway... and if the script fires too soon, the style won't be applied at all.
});
});
});
</script>
<?php endif;
// https://wordpress.org/support/topic/add-body_class-to-iframe-or-dynamically-add-class-references
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment