Allows you to easily embed a Google Slides slideshow in WordPress as a shortcode.
<?php
/**
* Google Slides embed shortcode
* The slideshow must be set to public!
*/
add_shortcode( 'googleslideshow','google_slideshow' );
function google_slideshow( $atts, $content = '' ) {
$atts = shortcode_atts( array(
'id' => NULL,
'height' => '550',
'start' => false,
'loop' => false
), $atts);
ob_start();
/**
* Shortened slideshow ID
* (for use as an element ID)
*/
$trimmedID = strtolower( substr( $atts['id'], 0, 10 ) );
?>
<?php if( $atts['id'] != NULL ) : ?>
<!-- [start] Google Slides - ID: <?php echo $atts['id']; ?> -->
<iframe
class="google-slideshow-iframe"
id="google-slideshow-<?php echo $trimmedID; ?>"
src="https://docs.google.com/presentation/embed?id=<?php echo $atts['id']; ?>&start=<?php echo $atts['start']; ?>&loop=<?php $atts['loop'];?>&"
frameborder="0"
width="100%"
height="<?php echo $atts['height']; ?>">
</iframe>
<!-- [end] Google Slides - ID: <?php echo $atts['id']; ?> -->
<?php else : ?>
<p style="font-weight:bold;color:red;padding:10px;margin:20px 0;background:#eee;">You did not specify a Google Slideshow ID!</p>
<?php endif; ?>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
?>