Last active
May 27, 2025 21:16
-
-
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.
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 | |
/** | |
* 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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment