Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danilostrazzullo/56525ed6a236fae5a824aaacf100ca9d to your computer and use it in GitHub Desktop.
Save danilostrazzullo/56525ed6a236fae5a824aaacf100ca9d to your computer and use it in GitHub Desktop.
Remove Custom Sidebars inheritance for child pages [ if you improve this solution, please, let me know :) ]
<?php
/**
* Remove Custom Sidebars inheritance for child pages
*
* The issue is described at the following link
* @link https://wordpress.org/support/topic/option-to-remove-inheritance
*/
function namespace_remove_inherited_sidebars( $replacements ) {
global $post;
if ( $post->post_parent != 0 && count($replacements) > 0 ) {
$post_id = $post->ID;
$post_meta = get_post_meta( $post_id, '_cs_replacements', true );
if ( ! is_array( $post_meta ) ) {
$post_meta = array();
}
if( empty($post_meta) ) {
return false;
} else {
foreach ($replacements as $key => $value) {
if ( empty($post_meta[$key]) ) {
unset($replacements[$key]);
}
}
}
}
return $replacements;
}
add_filter( 'cs_replace_sidebars', 'namespace_remove_inherited_sidebars' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment