I have the same issue like here: https://www.ads-software.com/support/topic/is_active_sidebar-detects-sidebar-but-it-is-not-active/#post-10699211
I wan’t to check if for an individual page a sidebar is active. The function “is_active_sidebar” checks it globally and not for the individual page..
Is there a function to check whether a sidebar for the rendered page is active? According to this info I am loading specific CSS classes to display the page without sidebars in full width.
PS: Is there a kind of documentation or api to read about all functions of this plugin?
Thank you!
Max
<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(“My Widget”) ) : ?>
<?php endif;?>
And in the function:
if ( function_exists(‘register_sidebar’) )
register_sidebar(array(
‘name’ => ‘My Widget’,
‘before_widget’ => ‘<div class = “My Widget”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h3>’,
‘after_title’ => ‘</h3>’,
)
);
?>
The new widget is created and I can find it in the back-end of my website.
In this widget I have put my polylang’s flags, but it has created an empty section in the header (I would like to have it at the right side with vertical alignment), in this empty section all flags work correctly, but if I try to move it through CSS only italian language is available, the other flags collapse their link… What can I do? Please and Thanks!
Paola
I am trying to add a custom body class if the widget is active on a certain page. In my case it is a slider.
add_filter('body_class', function (array $classes) {
if ( is_active_sidebar( 'slider' ) ) {
$classes[] = 'slider-active';
}
return $classes;
});
This filter adds the class without issue but it is showing on all pages even though my widget is only set to display on the Home/Front. Is there a way I can set it to only show on the pages it is active on by adding a variable to check if the widget option is set to visible?
]]>So if I choose 3, footer widget 1 and 2 work fine. When I add text, visual editor or anything in footer 3, it all shows up in footer 2 and footer 3 is blank white space.
If I choose 4 footer widgets. Whatever is in #3 shows up in #2 and #4 shows in #3 and #4 is blank white space.
When I deactivate, everything displays nicely and accurate except I lose control on what pages they display on.
Help.
I am using SociallyViral Theme 2.1 from mythemeshop
]]>Apologies in advance if this is a silly question. (Relative developer n00b.)
I’m working with a client’s custom plugin on a site. How it works is, you drag a widget that the plugin creates into its own custom sidebar. Then, on a page-by-page basis, you can enable this sidebar or disable it. What I’m trying to do is, if the page has the sidebar enabled, show that ‘custom’ sidebar, otherwise show a default.
Where I’m stuck is, is_active_sidebar
still returns true for the ‘custom’ sidebar even if the plugin returns false. Here’s my code:
<?php
if(function_exists('dynamic_sidebar')){
if(is_active_sidebar('sidebar_custom')){
dynamic_sidebar('sidebar_serivces_leadgen_footer');
}
elseif(is_active_sidebar('sidebar_serivces_secondary_footer')){
dynamic_sidebar('sidebar_serivces_secondary_footer');
}
}
?>
Is there a way to check if the sidebar content is an empty string (which is the case when the sidebar is disabled on a page)? Or to have the plugin make its sidebar ‘think’ that it’s empty by returning false or exiting or something like that?
Thank you in advance.
]]>The problem is that we need sidebar ID as argument for these functions.
Is there a way to get those ids (i.e: ca-sidebar-257836) using the custom “name” you assign to them???
If not, any custom function to check it they are empty?
Thanks in advance.
https://www.ads-software.com/plugins/content-aware-sidebars/
]]>Explanation:
I had a widget with widget logic set as:
is_category(‘xxx’) || in_category(‘xxx’)
the sidebar and widget were displayed with search results but is_active_sidebar() returned false.
If I changed the settings to:
is_category(‘xxx’) || in_category(‘xxx’) || is_search()
the sidebar and widget displayed with search results and is_active_sidebar() returned true.
Further, if I changed the settings to:
is_category(‘xxx’) || in_category(‘xxx’) && !is_search()
the sidebar and widget did not display with search results and is_active_sidebar() returned false.
If I removed all settings, the sidebar was displayed and is_active_sidebar() returned true.
Just FYI for anyone else with this problem.
I’m using is_active_sidebar() in the header to set a class for the body.
https://www.ads-software.com/plugins/widget-logic/
]]>I have a custom widget in a theme that in some cases (conditionally) returns false in its widget()
method, i.e. no HTML output.
The widget area is checked with is_active_sidebar()
(the function) before displaying the widgets and wrapping HTML.
Now, if there is a widget that outputs nothing, is_active_sidebar()
is still TRUE because there IS a widget in the sidebar and the wrapping HTML is displayed (an empty aside
for example).
I have a hacky solution with output buffering the widget area and checking if the string is empty.
As of WordPress 3.9. I found there is a new hook is_active_sidebar
(not the function) to manipulate is_active_sidebar() (the function). I would like to use this in the custom widget’s widget()
method to set is_active_sidebar
to FALSE when the widget returns false / outputs nothing, like the following, but it doesn’t work. How would I go about it?
function widget( $args, $instance ) {
extract( $args );
if ( $custom_condition ) {
add_filter( 'is_active_sidebar', '__return_false');
return false;
}
[...]
/* Output widget HTML. */
echo $output;
}
]]>