Last active
May 4, 2020 15:10
-
-
Save robertuniqid/ee9867fe0b0a39e8da901bedd59b0ae9 to your computer and use it in GitHub Desktop.
WPEP Center Section
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 | |
add_action('init', function () { | |
add_shortcode('ec_center', function ( $atts, $content ) { | |
$response = '<div class="wpep-center-section">'; | |
$response .= do_shortcode($content); | |
$response .= '</div>'; | |
return $response; | |
}); | |
}); | |
add_action('wp_footer', function () { | |
echo '<script type="text/javascript"> | |
jQuery(document).ready( function() { | |
jQuery(".wpep-center-section").each(function () { | |
let width = 0; | |
jQuery(this).find(" > *").each(function () { | |
width = width < parseInt(jQuery(this).width()) ? parseInt(jQuery(this).width()) : width; | |
}); | |
if (width <= 0) | |
width = jQuery(this).innerWidth() + 10; | |
jQuery(this).css("display", "block").css("margin-right", "auto").css("margin-left", "auto").css("width", width); | |
}); | |
}); | |
</script>'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's nothing "wrong" with this code, in the right circumstances it will work properly, but not always.
This is a hackish-style feature.