My WordPress environment is set up with 1 main site and many “sub” sites. They all have the same theme. Lambda by Oxygenna if that matters. I’m trying to centralize management of the footer so if it needs to be changed it only needs to be done once and not a dozen times.
I’m trying to us switch to blog https://codex.wordpress.org/WPMU_Functions/switch_to_blog
From what I understand switch_to_blog
should do the trick but it doesn’t seem to work as expected. I wrapped the entire footer in switch_to_blog(1)
so I would think that it should be pulling the footer widgets from site one and just using those but alas that is not the case.
Am I doing something wrong?
<?php
switch_to_blog(1);
global $oxy_theme;
$upper_footer_columns = $oxy_theme->get_option('upper_footer_columns');
$upper_footer_top = $oxy_theme->get_option('upper_footer_padding_top');
$upper_footer_bottom = $oxy_theme>get_option('upper_footer_padding_bottom');
$upper_footer_span = empty($upper_footer_columns) ? 'col-sm-12' : 'col-sm-' . (12 / $upper_footer_columns);
$show_upper_footer = oxy_check_show_footer('upper-footer-', $upper_footer_columns);
$footer_columns = $oxy_theme->get_option('footer_columns');
$footer_top = $oxy_theme->get_option('footer_padding_top');
$footer_bottom = $oxy_theme->get_option('footer_padding_bottom');
$footer_span = empty($footer_columns) ? 'col-sm-12' : 'col-sm-' . (12 / $footer_columns);
$show_footer = oxy_check_show_footer('footer-', $footer_columns);
$sub_footer_columns = $oxy_theme->get_option('sub_footer_columns');
$sub_footer_span = empty($sub_footer_columns) ? 'col-sm-12' : 'col-sm-' . (12 / $sub_footer_columns);
$show_sub_footer = oxy_check_show_footer('sub-footer-', $sub_footer_columns);
?>
<?php if ($upper_footer_columns > 0 && $show_upper_footer) : ?>
<section class="section section-upper-footer" >
<div class="container">
<div class="row element-top-<?php echo esc_attr($upper_footer_top); ?> element-bottom-<?php echo esc_attr($upper_footer_bottom); ?> footer-columns-<?php echo esc_attr($upper_footer_columns); ?>" >
<?php for($col = 0 ; $col < $upper_footer_columns ; $col++): ?>
<div class="<?php echo esc_attr($upper_footer_span); ?>">
<?php dynamic_sidebar('upper-footer-' . ($col+1)); ?>
</div>
<?php endfor ?>
</div>
</div>
</section>
<?php endif ?>
<?php if ($footer_columns > 0 && $show_footer) : ?>
<footer id="footer" role="contentinfo">
<section class="section">
<div class="container">
<div class="row element-top-<?php echo esc_attr($footer_top); ?> element-bottom-<?php echo esc_attr($footer_bottom); ?> footer-columns-<?php echo esc_attr($footer_columns); ?>">
<?php for ($col = 0 ; $col < $footer_columns ; $col++): ?>
<div class="<?php echo esc_attr($footer_span); ?>">
<?php dynamic_sidebar('footer-' . ($col+1)); ?>
</div>
<?php endfor ?>
</div>
</div>
</section>
<?php if ($sub_footer_columns > 0 && $show_sub_footer) : ?>
<section class="section subfooter">
<div class="container">
<div class="row element-top-10 element-bottom-10 footer-columns-<?php echo esc_attr($sub_footer_columns); ?>">
<?php for ($col = 0 ; $col < $sub_footer_columns ; $col++): ?>
<div class="<?php echo esc_attr($sub_footer_span); ?>">
<?php dynamic_sidebar('sub-footer-' . ($col+1)); ?>
</div>
<?php endfor ?>
</div>
</div>
</section>
<?php endif; ?>
</footer>
<?php endif; ?>
</div>
<?php
wp_footer();
restore_current_blog();
?>
</body>
</html>