Created
May 2, 2017 13:42
-
-
Save ben-heath/ad378cf07fd568b5e80494ba9822a906 to your computer and use it in GitHub Desktop.
Example Respondo Bootstrap modal shortcode
This file contains 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 | |
/* Bootstrap Docs: | |
* http://getbootstrap.com/javascript/#modals | |
* Lots of options could be added as attributes in the shortcode. The attached code is just the pieces I needed at the time. | |
* This is the simple shortcode: | |
* [sls-modal id="modal-1" header_text="HEADER TITLE HERE"] | |
* CONTENT HERE | |
* [/sls-modal] | |
* One thing that should be changed, is to allow for other respondo shortcode to be used within the content part. | |
* I hadn't shorted that out yet. | |
*/ | |
// Add Shortcode | |
function sls_modal_shortcode( $atts , $content = null ) { | |
// Attributes - Easilly add more as needed | |
extract( shortcode_atts( | |
array( | |
'id' => 'modal-1', | |
'header_text' => 'Modal Header', | |
), $atts ) | |
); | |
// code , Could run without the buffer. | |
ob_start(); | |
$modal = '<div id="' . esc_attr($id) . '" class="modal fade" role="dialog" aria-hidden="true" style="display: none;"> | |
<div class="modal-dialog"> | |
<!-- Modal content--> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal">×</button> | |
<h3 class="modal-title">' . esc_attr($header_text) . '</h3> | |
</div> | |
<div class="modal-body"> | |
' . $content . ' | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<button type="button" class="btn btn-default btn-medium" data-toggle="modal" data-target="#' . esc_attr($id) . '">Learn More</button>'; | |
$modal .= ob_get_contents(); | |
ob_end_clean(); | |
return $modal; | |
} | |
add_shortcode( 'sls-modal', 'sls_modal_shortcode' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment