$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WP renders HTML wrong when adding widgets|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WP renders HTML wrong when adding widgets

matteradmin9PV0评论

Here is my code for a footer. Footer element should have div.footer-widgets, nav, and p elements as children. But for some reason wordpress puts everything to div.footer-widget element (I've included the screenshot).

This happens only after adding dynamic_sidebar. What is happening here?

<footer class="site-footer">

    <div class="footer-widgets">
        <p>Child1</p>    
        <p>Child2</p>   
        <?php
            if(is_active_sidebar('footer_1'))
            {
                dynamic_sidebar('footer_1');
            }
        ?>
    </div> <!-- End of footer-widget -->

    <nav class="site-nav">
        <?php 
            $arg = array(
                'theme_location' => 'footer',
                'menu_class' => 'navigation'
            );
        ?>
        <?php wp_nav_menu($args); ?>
    </nav>

    <p><?php bloginfo('name');?> &copy; <?php echo date('Y'); ?></p>
</footer>

<?php wp_footer();?>

</body>
</html>

Also, code for registering a sidebar in functions.php file

function our_widget_init() {

    register_sidebar(array(
    'name'=> 'Footer Area 1',
    'id' => 'footer_1',
    'before_widget' => '<div>',
    'after_widget' => '</div',
    'before_title' => '<h2>',
    'after_title' => '</h2>'
    ));
 }
add_action('widgets_init', 'our_widget_init');

Here is my code for a footer. Footer element should have div.footer-widgets, nav, and p elements as children. But for some reason wordpress puts everything to div.footer-widget element (I've included the screenshot).

This happens only after adding dynamic_sidebar. What is happening here?

<footer class="site-footer">

    <div class="footer-widgets">
        <p>Child1</p>    
        <p>Child2</p>   
        <?php
            if(is_active_sidebar('footer_1'))
            {
                dynamic_sidebar('footer_1');
            }
        ?>
    </div> <!-- End of footer-widget -->

    <nav class="site-nav">
        <?php 
            $arg = array(
                'theme_location' => 'footer',
                'menu_class' => 'navigation'
            );
        ?>
        <?php wp_nav_menu($args); ?>
    </nav>

    <p><?php bloginfo('name');?> &copy; <?php echo date('Y'); ?></p>
</footer>

<?php wp_footer();?>

</body>
</html>

Also, code for registering a sidebar in functions.php file

function our_widget_init() {

    register_sidebar(array(
    'name'=> 'Footer Area 1',
    'id' => 'footer_1',
    'before_widget' => '<div>',
    'after_widget' => '</div',
    'before_title' => '<h2>',
    'after_title' => '</h2>'
    ));
 }
add_action('widgets_init', 'our_widget_init');
Share Improve this question edited Jan 24, 2019 at 11:23 zxdmac asked Jan 24, 2019 at 10:11 zxdmaczxdmac 32 bronze badges 2
  • What's your code for registering the 'footer_1' sidebar? – Jacob Peattie Commented Jan 24, 2019 at 10:25
  • Sorry, added it to the end of the post – zxdmac Commented Jan 24, 2019 at 11:25
Add a comment  | 

1 Answer 1

Reset to default 0

You're missing > in the closing div, for after_widget:

'after_widget' => '</div',

Needs to be:

'after_widget' => '</div>',

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far