im trying to display a specific widget i need for the header current im using a code to display all widgets but my problem is that if I add additional widgets it will destroy my site.

                        <?php dynamic_sidebar( 'sidebar2' ); ?>

                    <?php else : ?>

                        <!-- This content shows up if there are no widgets defined in the backend. -->

                        <div class="alert-box">Please activate some Widgets.</div>

                    <?php endif; ?>

code im using..

im trying to display this widget


i tried to use this code to call the widget but nothing happens I must be putting the wrong name of the widget or the code. i don't about backend code.

<?php the_widget( 'WP_Language_Switcher' ); ?> 
  • can i use this to display the widget? prntscr.com/4yv0n0 – MIke Oct 23 '14 at 8:01
  • Where is widget coming from? I don't think it's native WordPress one. – Rarst Oct 23 '14 at 9:54
  • its coming from a plugin. is it plausible to call? or i need another plugin to call it? – MIke Oct 23 '14 at 10:08
  • You probably just need to figure out correct class name from the plugin's source. – Rarst Oct 23 '14 at 10:25
  • yeah the problem is i dont know the name of the widget. i tried to get it using the developer tool for chrome checking the class and id. i tried to use both but nothing happen i dont know if i the widget is wrong or the syntax Im using to call is wrong... <?php the_widget( 'WP_Language_Switcher' ); ?> I'm using this code btw – MIke Oct 24 '14 at 0:24

you can create new widget area.

     function header_widget_areas() {

    register_sidebar( array(
        'name' => __( 'header', 'header' ),
        'id' => 'header',
        'description' => __( 'Insert something for about us text.', 'header' ),
        'before_widget' => '<div class="widget span3">',
        'after_widget' => '</div>',
        'before_title' => '<h4>',
        'after_title' => '</h4>',
    ) );

add_action('widgets_init', 'header_widget_areas');

Then place your widget in that area from appearance. Then in your template where you want to display widget past this code.

<?php if (function_exists('header_widget_areas')): ?>

                                                <?php dynamic_sidebar('header'); ?> 
                                            <?php endif; ?>
  • this doesnt actually answers my question but this is the best alternative so far. – MIke Oct 27 '14 at 5:00
  • how can add a condition if my site has a multilanguage like abc.com/abd/en for english site and abc.com/abd/da for dansk – MIke Oct 27 '14 at 5:44
  • I have no knowledge about that language condition. Sorry dear. – Lemon Kazi Nov 3 '14 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.