Created
June 30, 2023 22:30
-
-
Save pingram3541/81dd0e5e72bc71638b68e1d63ae8a5e5 to your computer and use it in GitHub Desktop.
Canvas (like) template when editing Elementor "Section" Templates
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 | |
/** | |
* Removes header & footer when editing Elementor Section templates | |
* | |
* Action: adds inline css to hide elements | |
* | |
* see Elementor issue: https://github.com/elementor/elementor/issues/6297 | |
* | |
* How to use: add this file to your child theme and include it in your functions.php adding: | |
* include_once( 'is-section-template.php' ); | |
* | |
**/ | |
// Exit if accessed directly. | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
// Step 1: check if editing an Elementor "section" template | |
if ( ! function_exists( 'is_section_template' ) ){ | |
function is_section_template() { | |
if ( get_post_meta( get_the_ID(), '_elementor_template_type', true ) == 'section' ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} | |
// Step 2: load css to hide header/footer | |
add_action('wp_head', function(){ | |
if( is_section_template() ){ | |
$html = '<style type="text/css">'."\n"; | |
$html .= '.elementor-location-header,'."\n"; | |
$html .= '.elementor-location-footer,'."\n"; | |
$html .= '.page-header { '."\n"; | |
$html .= ' display: none;'."\n"; | |
$html .= '}'."\n"; | |
$html .= '</style>'; | |
echo $html; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment