Skip to content

Instantly share code, notes, and snippets.

@sokoljr
Created January 18, 2017 14:47
Show Gist options
  • Save sokoljr/0d7c36dbcac199d4156356e93e0ea2a1 to your computer and use it in GitHub Desktop.
Save sokoljr/0d7c36dbcac199d4156356e93e0ea2a1 to your computer and use it in GitHub Desktop.
Modal on wp whith JSON
<script>
<?php
$slotIds = array(46, 98); //id pages
$modals = array();
foreach( $slotIds as $current_id ) {
$cntnt = '';
$post = get_post($current_id);
$cntnt .= $post->post_content;
$cntnt .= do_shortcode('[_moneyGame]');
;
array_push( $modals, array( "id" => $current_id, "content" => $cntnt ) );
}
$modals_json = json_encode( $modals, JSON_UNESCAPED_UNICODE );
$modals_json = preg_replace( '/(\\\\"|\')/', '\\\\\\0', $modals_json);
$modals_json = preg_replace( '/(\\\\n|\\\\r)/', '', $modals_json );
$modals_json = preg_replace( '/document\.write\(/', 'jQuery(\\\'#modal_form .embed-responsive\\\').append(', $modals_json );
echo 'modals = JSON.parse(\'' .$modals_json. '\');';
?>
</script>
<div id="modal_form">
<span id="modal_close"><i class="fa fa-times-circle-o fa-5px" aria-hidden="true"></i></span>
<div class="modal_body">
</div>
</div>
<div id="overlay"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment