Initial
This commit is contained in:
29
modal-theme-part/gutenberg-modal.php
Normal file
29
modal-theme-part/gutenberg-modal.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* Prevent user from adding the modal being added to any templates */
|
||||||
|
|
||||||
|
|
||||||
|
function restrict_modal_block_in_templates( $allowed_blocks, $post ) {
|
||||||
|
// Check if it's in the admin area (where users edit content)
|
||||||
|
if ( is_admin() && $post->post_type !== 'page' ) {
|
||||||
|
// Prevent the modal block from being added in any post or template
|
||||||
|
$allowed_blocks = array_diff( $allowed_blocks, ['your-theme/modal'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $allowed_blocks;
|
||||||
|
}
|
||||||
|
add_filter( 'allowed_block_types', 'restrict_modal_block_in_templates', 10, 2 );
|
||||||
|
|
||||||
|
/* Add the modal to the footer (or optionally use wp_head to add it to the header) */
|
||||||
|
|
||||||
|
function add_modal_to_every_page() {
|
||||||
|
// Get the modal content from the theme part or reusable block
|
||||||
|
$modal_content = get_theme_part( 'modal' ); // Assuming get_theme_part is a custom function to fetch your modal content.
|
||||||
|
|
||||||
|
if ( $modal_content ) {
|
||||||
|
echo '<div class="custom-modal">';
|
||||||
|
echo $modal_content;
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'wp_footer', 'add_modal_to_every_page' );
|
||||||
Reference in New Issue
Block a user