I have a calendar plugin I wish to use, I tested it first on the WP '17 default theme and it displays just fine. I have my own custom theme I'm building using w3.css, very basic stuff.
I created a display area for widgets using
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
add_theme_support( 'customize-selective-refresh-widgets' );
wp_enqueue_script("jquery");
?>
And put the following in an appropriate div within my index.php:
<?php dynamic_sidebar( 'home_right_1' ); ?>
As far as I can tell, when my "theme" outputs the widget there is no stylesheet attached to it. It's a calendar widget and displays the entire list of days of the month in a long list, rather than an enclosed area.
Any suggestions would be appreciated.
Okay, I hadn't called the footer which is apparently where the function hooks to. Now it's working as expected.
<?php get_footer(); ?>
(Placed just before </body> in the index file.)
I also ended up using the following to call it:
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
Related
I can't create left sidebar.
I created a file into child theme folder: sidebar-left.php:
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>
<aside class="sidebar">
<!-- SIDEBAR WIDGET AREA -->
<?php if ( is_active_sidebar( 'lhsidebar' ) ) : ?>
<?php dynamic_sidebar( 'lhsidebar' ); ?>
<?php else : ?>
<p><?php esc_html_e('No widgets added', 'rehub-theme'); ?></p>
<?php endif; ?>
</aside>
Then, I have added this code into child theme's function.php:
// Left SideBar
register_sidebar( array(
'name' => esc_html__( 'Left Sidebar', 'rehub' ),
'id' => 'lhsidebar',
'description' => esc_html__( 'Add widgets here.', 'rehub' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
But where should I put the get_sidebar('sidebar-left')?
You have to call the sidebar inside any template of your child theme either by using the get_sidebar() function:
<?php get_sidebar('left'); ?>
Note: the name of the file without sidebar- part at the begin of the name as mentionned in the doc.
Either by using the get_template_part() function if your template file is not in the same directory as the sidebar file.
<?php get_template_part( 'sidebar-templates/sidebar', 'left' ); ?>
Note: here the full name of the sidebar is mentionned in the function, as well as its path from the root of the child-theme, cf doc.
I've created a custom widget area in the plugin I'm creating.
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
dynamic_sidebar( 'home_right_1' );
And to enable showing the widgets stored in this widget I have inserted this code inside the footer.php of the theme I'm currently using for testing.
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-
area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
It works, when I add widgets to my widget area, they are shown in footer of the website. But I want to make the plugin works without changing the footer.php manually. How can I check which theme is activated and then find that theme, the footer.php file and add that code exacltly where I want (to be shown below any other footer created with the theme when is installed. Also, I would like to remove the footer that was generated before.
i am working on a simple WordPress blog and i am trying to display a widget that appears in every page in the website .. i have followed the dynamic sidebar widget approach, but the problem ,
here is the Function.php file
function wpb_widgets_init() {
register_sidebar( array(
'name' => 'Custom Header Widget',
'id' => 'custom-header-widget',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="chw-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpb_widgets_init' );
and my header.php file
<?php if ( is_active_sidebar( 'custom-header-widget' ) ) : ?>
<div id="header-widget-area" class="chw-widget-area widget-area" role="complementary">
<?php dynamic_sidebar( 'custom-header-widget' ); ?>
</div>
<?php endif; ?>
and this works fine only in any single post.
but in the home page/or any template file nothing shows !!!
Any ideas ?
You can try this structure and make sure your sidebar active
I have figured it out
i hade to create a template file for my new sideBar called: sidebar-.php
and use the get_sidebar(id) method to call it
Voilet it works in all templates ...
I followed the instructions here for how to add a widget to a template. I added this code to functions.php:
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Carousel',
'id' => 'carousel_widget',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
and I added this to my custom template:
<?php if ( is_active_sidebar( 'carousel_widget' ) ) : ?>
<div id="carousel-widget" class="carousel widget-area">
<?php dynamic_sidebar( 'carousel_widget' ); ?>
</div>
<?php endif; ?>
It worked, but my new widget showed up as a sidebar, and I want it to be in the main body of the page. Obviously this is because of the dynamic_sidebar function, but the documentation is not very helpful on how to place a widget on the page NOT as a sidebar.
I tried replaced the php with this:
<div id="carousel-widget" class="carousel widget-area">
<?php the_widget( 'carousel_widget' ); ?>
</div>
But now it doesn't show up at all.
How do I place this widget on my page without it showing up as an absolutely positioned sidebar?
I'm working the first time with WordPress, now I'm trying to add a custom Widget to an HTML box.
The HTML: The blank News box
I started to read a bit about widgets and the tutorials told me to create a new Widget area inside my functions.php document, which i did with the following code:
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
?>
Now i went into my index.php document, which stores the HTML so I tried to add the following code to the HTML blank news box:
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
After i finished this also, i went into my WordPress admin menu and applied the plugin to the widget.
But it wouldn't show up...
Does anyone have a idea why?
update your index.php code as below:
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>