Last active
August 29, 2015 14:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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