douziqian2871 2015-05-04 20:54
浏览 110
已采纳

Wordpress主题调试:插件侧边栏导致原始侧边栏不显示

I have determined that my plugin code works perfectly fine in other themes, but in the theme: Magazinly, the sidebar plugin I wrote, causes the sidebar not to display. Through debugging, I've determined that the sidebars register, and two sidebar arrays are created, but one is not populated.

Here is the plugin code:

register_sidebar(array(
        'name'=>'Bottom Widget Area',
        'id'=> 'bottom-widget',
        'before_widget' => '<aside class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<div class="block-title"><span>',
        'after_title' => '</span></div>'
    ));

include 'add_bottom_bar.php';

This is add_bottom_bar.php:

    // Register Bottom_Bar
function add_bottom_widget(){

    echo '<div class=\'bottombar\'>';
    if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('bottom-widget')) : 
        endif;
    echo '</div>'; 
}

 add_action ('get_footer', 'add_bottom_widget');


// Register style sheet.
add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );


// Register style sheet.
function register_plugin_styles() {
    wp_register_style( 'custom_widget_final', plugins_url( 'custom_widget_final/css/bottom_bar.css' ) );
    wp_enqueue_style( 'custom_widget_final' );
}

And here is the code for the sidebar in Magazinly:

http://pastebin.com/eJu7Wk3C

There's also this code that appears to use whatever this thing the theme creator called 'dinamic sidebar' to... well... I would imagine... render dynamic sidebars :

http://pastebin.com/T0LW3QTS

But, my guess is that this is the culprit: The Magazinly theme uses this sidebar loader, but it seems like serious overkill. I am guessing that the sidebar widget I'm registering, is disrupting this sidebar loader.

http://pastebin.com/jCtvjVqC

With all code presented, my next question is: what are my options? I need to add widget positions to three sites, all using the same theme, but preserve the sidebar. Presently, if I activate my plugin, the sidebar won't load, but the plugin works. If I deactivate the plugin, the sidebar returns. Both are important, but I cannot modify the theme, and creating a child theme seems excessive. I'd prefer to debug this theme, and use widgets.

Here's what I have tried/tested:

  1. Tested this plugin on four other WP sites. No issues. Sidebars render fine. Plugin works like a charm.

  2. On problem site: wp_debug, set to true... throws no errors, but gives a warning for each of the theme's native sidebars (no id set, which is a pre 4.1 thing). To my knowledge, it does not affect anything.

  3. I removed the include at the bottom, just to narrow down where the problem could be in my code. I determined that even when the css enqueue is disabled, or even if add_bottom_bar.php is not included, the theme's native sidebars still break. This makes it abundantly, totally clear to me that there is a register_sidebar conflict.

  4. I've looked at the source when the plugin is activated, and when it is deactivated. I find after diffing the source, when the plugin is activated, the sidebars do not show in the source, so it is not a css/js thing, as far as I can tell.

What, if any workaround might there be for this? A widget would greatly improve workflow, but I'm beginning to consider that letting go of the sidebar/widget situation might be smarter.

Any hints, tips, or insight? I know my question is a bit general, but I've hit a brick wall, here, in trying to stay hands-off with this theme code.

Any help would be much appreciated! Thanks!

  • 写回答

1条回答 默认 最新

  • douan8473 2015-05-04 22:57
    关注

    Ok. Figured it out.

    add_action( 'widgets_init', 'bottom-widget' );
    

    Needed to initialize the widget right after registering the sidebar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样