I want to place an advert on the side bar, but the widget area appears in the wp-admin panel(appearance>widgets)
However, when I place my ad in the Side bar widget area, it does not appear on the site.
I used the code below to create the widget area and placed it in fuctions.php file of my theme. Where am I going wrong?
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Sidebar Widgets',
'id' => 'sidebar-widgets',
'description' => 'Widget Area',
'before_widget' => '<div id="one" class="two">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}
I'll be grateful.
Below is my page template.
<?php
/**
The template for displaying all pages.
*/
get_header();
?>
<div id="main" class="<?php echo $solid_content_class; ?> clearfix" role="main">
<?php
do_action('solid_before_content');
while ( have_posts() ) : the_post();
get_template_part( 'lib/content/content', 'page' );
endwhile; // end of the loop.
do_action('solid_after_content');
// If the theme supports comments in pages and comments are open or we have at least
one comment, load up the comment template
if( solid_theme_supports( 'comments', 'pages' ) && ( comments_open() || '0' !=
get_comments_number() ) ) comments_template( '', true );
?>
</div><!-- #main -->
<?php if( $solid_sidebar_location === 'left' || $solid_sidebar_location === 'right' )
{ ?>
<aside id="sidebar" class="sidebar <?php echo $solid_sidebar_class; ?>">
<div id="sidebar-main" class="sidebar">
<?php get_sidebar(); ?>
</div><!--sidebar-main-->
</aside>
<?php }
get_footer(); ?>'
function debatingday_widgets_init()
{
// Primary Widget area (left, fixed sidebar)
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'debatingday' ),
'id' => 'primary-widget-area',
'description' => __( 'Here you can put one or two of your main widgets (like an intro text, your page navigation or some social site links) in your left sidebar. The sidebar is fixed, so the widgets content will always be visible, even when scrolling down the page.', 'debatingday' ),
'before_widget' => '<div class="s-widget" id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h5><i class="fa fa-folder-open color"></i> ',
'after_title' => '</h5>',
) );
// Secondary Widget area (right, additional sidebar)
register_sidebar( array(
'name' => __( 'Secondary Widget Area', 'debatingday' ),
'id' => 'secondary-widget-area',
'description' => __( 'Here you can put all the additional widgets for your right sidebar.', 'debatingday' ),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
/* Register sidebars by running debatingday_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'debatingday_widgets_init' );
Related
I want to show a 336px width second sidebar (left side on all pages) for destop/tv screens wider than 1682px.
If the second sidebar has its own class then I can hide it with the {display: none;} CSS tag inside the media query feature.
Currently, my template only has 1 sidebar which can be shown either on the right side or left side. It is currently on the right side.
This script is already present on my functions.php
/*-----------------------------------------------------------------------------------*/
// Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
// To override skeleton_widgets_init() in a child theme, remove the action hook and add your own
// function tied to the init hook.
/*-----------------------------------------------------------------------------------*/
if ( !function_exists( 'skeleton_widgets_init' ) ) {
function skeleton_widgets_init() {
// Area 1, located at the top of the sidebar.
register_sidebar( array(
'name' => __( 'Posts Widget Area', 'smpl' ),
'id' => 'sidebar-1',
'description' => __( 'Shown only in Blog Posts, Archives, Categories, etc.', 'smpl' ),
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
register_sidebar( array(
'name' => __( 'Pages Widget Area', 'smpl' ),
'id' => 'sidebar-2',
'description' => __( 'Shown only in Pages', 'smpl' ),
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 3, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'First Footer Widget Area', 'smpl' ),
'id' => 'footer-widget-area-1',
'description' => __( 'The first footer widget area', 'smpl' ),
'before_widget' => '<div class="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 4, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Second Footer Widget Area', 'smpl' ),
'id' => 'footer-widget-area-2',
'description' => __( 'The second footer widget area', 'smpl' ),
'before_widget' => '<div class="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 5, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Third Footer Widget Area', 'smpl' ),
'id' => 'footer-widget-area-3',
'description' => __( 'The third footer widget area', 'smpl' ),
'before_widget' => '<div class="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 6, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Fourth Footer Widget Area', 'smpl' ),
'id' => 'footer-widget-area-4',
'description' => __( 'The fourth footer widget area', 'smpl' ),
'before_widget' => '<div class="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
/** Register sidebars by running skeleton_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'skeleton_widgets_init' );
}
/** Next code follows from this point...
This is the code present on sidebar.php
<?php
/**
* The Sidebar containing the primary blog sidebar
*
*/
// hide sidebars with sidebars=false custom field
if (is_singular() && get_post_meta($post->ID, "sidebars", $single = true) == "false") {
return;
}
if ( is_active_sidebar( 'sidebar-1' ) ) {
do_action('skeleton_before_sidebar');
dynamic_sidebar( 'sidebar-1' );
do_action('skeleton_after_sidebar');
}
?>
As per this guide, https://wordpress.stackexchange.com/questions/135403/display-sidebar-that-created-in-functions-php , I added the code of the first answer to the functions.php file
// 2nd Sidebar
add_action( 'widgets_init', 'wpsites_add_widget' );
function wpsites_add_widget() {
register_sidebar(array(
'name'=>'Sidebar-Aries',
'id' => 'sidebar-aries',
'description' =>'Display all the contents of sidebar at Aries page.',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
}
Then added the other code into the single.php file
<?php
/**
* The Template for displaying all single posts.
*
* #package WordPress
* #subpackage skeleton
* #since skeleton 0.1
*/
get_header();
do_action('skeleton_before_content');
get_template_part( 'loop', 'single' );
do_action('skeleton_after_content');
get_sidebar();
get_footer();
<?php if ( is_active_sidebar( 'sidebar-aries' ) ) : ?>
<ul id="sidebar">
<?php dynamic_sidebar( 'sidebar-aries' ); ?>
</ul>
<?php endif; ?>
?>
Then I visited Appearance > Widgets and checked if there is any new sidebar but there is none.
I also tried the code from another question but it didn't work for me as well.
Then I followed this guide - https://smallbusiness.chron.com/build-website-php-sidebar-60499.html
Step: 5 - Locate the lines of code that register the sidebars in
"functions.php" -- they are usually near the top. Edit the code to
make “register_sidebar” plural, and add a number “2” between the
brackets in the line below, like this:
if ( function_exists('register_sidebars') ) register_sidebars(2);
Click "Update File." The sidebar is now available by going to
"Appearance" and then "Widgets."
But the code present on my functions.php looks a bit different and it didn't work.
What should I do?
STEP I: Open the functions.php and paste the following codes:
function __widgets_init() {
register_sidebar( array (
'name' => __('2nd Sidebar', 'textdomain'),
'id' => 'sidebar-secondary',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', '__widgets_init' );
STEP II: Now, copy the sidebar.php and paste it and rename it into: sidebar-secondary.php. Now erase all the codes inside, and paste the following:
<aside id="sidebar-secondary-wrapper" role="complementary">
<?php if ( is_active_sidebar('sidebar-secondary') ) : ?>
<div id="secondary" class="widget-area">
<ul class="xoxo">
<?php dynamic_sidebar('sidebar-secondary'); ?>
</ul>
</div>
<?php endif; ?>
</aside>
STEP III: Get into the index.php or any other files you want. Paste the code get_sidebar( 'secondary' ); in the appropriate places in the get_sidebar(); or get_footer(); sections as follows::
<?php get_header();
// paste here: get_sidebar( 'secondary' );
...
...
or
<?php get_header();
...
...
// paste here: get_sidebar( 'secondary' );
get_sidebar();
get_footer();
?>
STEP IV:
Now your layout consists of two sidebars. Rest is up to you.
#media screen and (max-width: 1681px) {
#secondary-sidebar-wrapper {
display: none !important;
}
}
I want to add a widget that will only appear on the shop page, but I couldn't get any results.
functions.php
function kucuksun_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'kucuksun' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'kucuksun' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
),
register_sidebar(
array(
'name' => esc_html__( 'Shop', 'kucuksun' ),
'id' => 'shop',
'description' => esc_html__( 'Add widgets here.', 'kucuksun' ),
'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', 'kucuksun_widgets_init' );
Following my code: sidebar.php
<?php
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside>
I'm not exactly sure but I need to print it in
woocommerce.php dynamic_sidebar( 'shop' );
To create a sidebar with widgets that will only appear on the shop page,
you can apply the following simple steps:
Create a new php file, name it sidebar-shop.php and place it in your themes root folder
Copy/paste the code from sidebar.php to sidebar-shop.php
Place a widget in the sidebar, and it should only be visible on the shop page
Explanation: page-{slug}.php — If no custom template has been assigned, WordPress looks for and uses a specialized template that contains the page’s slug.
i'm programming a plugin in php for wordpress for managing widgets, their places in a page and in which page they should appear. I'm having problems because i can't activate my sidebar and i dont know why. I post my code to see if something is not right and you can help me. this first file is the functions.php that, in theory, should register sidebars.
require_once('widgets.php');
function my_register_sidebars(){
// Register the 'primary' sidebar.
register_sidebar(
array(
'id' => 'primary',
'name' => __('Primary Sidebar'),
'description' => __('A short description of the sidebar.'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'id' => 'adios',
'name' => __('adios'),
'description' => __('A short description of the sidebar.'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
}
add_action('widgets_init', 'my_register_sidebars');
after a series of try-outs, I have also seen that add_action is not doing his work, do you have answers about it?
After that i instantiated a new file(sidebar.php) to recall the sidebar.
<?php
if (is_active_sidebar('primary')) : ?>
<aside id="secondary" class="sidebar widget-area" role="complementary" style="background-color = 'black';">
<?php dynamic_sidebar('primary'); ?>
</aside><!-- .sidebar .widget-area -->
<?php endif; ?>
And finally to call the sidebar i use get_sidebar();
but i cannot show the sidebar and it seems it is not even active.
do you have also ideas on how i can add widgets to this "activated" sidebar?
Thank you for your helps.
Use this code in your function.php
function my_custom_sidebar() {
register_sidebar(
array (
'name' => __( 'Custom', 'your-theme-domain' ),
'id' => 'custom-side-bar',
'description' => __( 'Custom Sidebar', 'your-theme-domain' ),
'before_widget' => '<div class="widget-content">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);} add_action( 'widgets_init', 'my_custom_sidebar' );
And put this code to your template file
<?php if ( is_active_sidebar( 'custom-side-bar' ) ) : ?>
<?php dynamic_sidebar( 'custom-side-bar' ); ?>
Try This code
Hi everyone i am developing a theme for wordpress i read a lot for dynamic sidebar but they aren't work my function code :
<?php
if ( function_exists('dynamic_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="wcon">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
?>
and my sidebar.php code :
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
and i am geting sidebar.php using this code :
<?php get_sidebar(); ?>
It seems be fine but i can't add widget to it no link in wordpress panel and no direct access.
In your functions.php
add this below
//initialize addiional sidebars.
if(function_exists('register_sidebar')){
register_sidebar(
array(
'name' => 'second-sidebar' ,
'id' => 'second-sidebar',
'before_widget' => '<li class ="widget-container>"',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);}
then where ever you want it to appear, add this
<?php dynamic_sidebar('second-sidebar'); ?>
Then go to your wordpress backend, in the widgets area, youll see a "second-sidebar" tab on the right hand side. Drop in your widgets and you should be good to go.
hope this helps
Try this instead:
functions.php
add_action( 'widgets_init', 'my_register_sidebars' );
function my_register_sidebars() {
register_sidebar(
array(
'id' => 'primary',
'name' => __( 'Primary' ),
'description' => __( 'Main Sidebar' ),
'before_widget' => '<div class="wcon">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
)
);
}
sidebar.php
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php dynamic_sidebar('primary'); ?>
<?php endif; ?>
Here is a simpler answer:
//sidebar php file
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-name') ) : ?>
<p>You're not using a dynamic sidebar</p>
<?php endif; ?>
//functions.php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name'=>'sidebar-name',
'before_widget' => '<div class="your-class">',
'after_widget' => '</div>',
'before_title' => '<h2>', //h3, h4, h5, whatever size header you prefer
'after_title' => '</h2>',
));
I've found a widget that I need to add to more than one sidebar widget area.
However, apparently its been coded so that once you drag it from "available widgets" over to a sidebar widget, it disappears from the "available widgets" listing.
here is the code from the functions.php
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Blog Widgets',
'id' => 'sidebar-widgets',
'description' => 'Widget Area',
'before_widget' => '<div id="one" class="two">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}
here is the code from my index.php
<p><?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Widgets') ) : ?>
<?php endif; ?></p>
you help will appreciated
thank you