Skip to content

Instantly share code, notes, and snippets.

@bloqhead
Last active May 27, 2025 21:16
Show Gist options
  • Save bloqhead/0771909ae4f5325d9198 to your computer and use it in GitHub Desktop.
Save bloqhead/0771909ae4f5325d9198 to your computer and use it in GitHub Desktop.
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']; ?>&amp;start=<?php echo $atts['start']; ?>&amp;loop=<?php $atts['loop'];?>&amp;"
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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment