-1

I want to display a widget outside the sidebar, but I can't get my code to work.

The theme name is radius-primary-sidebar and my widget id is text-20 (according to the html in the admin page. See image #1).

I've tried using the_widget("radius-primary-sidebar", "widget-id=text-20"), but that didn't return anything.

What I'm I doing wrong?

I'm using wordpress 3.5.2.

From /wp-admin/widgets.php in the admin panel.

enter image description here

  • Where exactly outside the sidebar? You're referring to a native widget where the i.d changes each time you use a different text widget. I assume you want to create a new widget area? – Brad Dalton Apr 17 '14 at 11:50
  • I want to display a single widget in the bottom of my mobile site. – user50462 Apr 17 '14 at 11:56
  • How are you generating your mobile site? – Brad Dalton Apr 17 '14 at 12:06
0

According to the codex, the first argument should be a valid widget class name and not the theme name.

<?php the_widget( 'Replace_With_Valid_Widget_Class_Name', 'widget-id=text-20' ); ?>
0

This is how you add a widget from your functions file.

Note: Only displays on mobiles.

//functions.php
function wpsites_register_widget() {

 register_sidebar( array(
'name' => 'Bottom Widget',
'id' => 'bottom-widget',
'before_widget' => '<div>',
'after_widget' => '</div>',
) );
}

add_action( 'widgets_init', 'wpsites_register_widget' );

add_filter( 'loop_end', 'bottom_widget', 25 );

function bottom_widget() {

if ( wp_is_mobile() && is_active_sidebar( 'bottom-widget' ) ) { 
dynamic_sidebar('bottom-widget', array(
'before' => '<div class="bottom-widget">',
'after' => '</div>',
) );
     }

}

You can change the loop_start hook to loop_end or use any other WordPress or theme specific hook.

You can also add the widget in a template file like single.php

<?php if ( wp_is_mobile() && is_active_sidebar( 'bottom-widget' ) ) : ?>
<ul id="bottom-widget">
<?php dynamic_sidebar( 'bottom-widget' ); ?>
</ul>
<?php endif; ?>

Uses wp_is_mobile() to check if browser being used on a mobile device.

You should use CSS Media Queries to style your widget for display on different sized mobile devices.

0

Please Try with bellow inside functions.php

function wpsites_register_widget() {
 register_sidebar( array(
'name' => 'Bottom Widget',
'id' => 'bottom-widget',
'before_widget' => '<div>',
'after_widget' => '</div>',
) );

Copy the code and pastest as you want to show the widgets

if (is_active_sidebar( 'bottom-widget' ) ) :
dynamic_sidebar( 'bottom-widget' ); 
endif;

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.