I've tried many variations and can't seem to get the syntax right. In one of my Wordpress theme pages I have the following Widget code. I want to append the existing functionality to where it removes this widget if the page name is 'event-view' or page id is '640'...how do I do this?
<?php
// A third sidebar for widgets
if ( is_active_sidebar( 'third-widget-area' ) ) : ?>
<div id="third" class="widget-area" role="complementary">
<ul class="xoxo">
<?php dynamic_sidebar( 'third-widget-area' ); ?>
</ul>
</div><!-- #secondary .widget-area -->
Try this:
<?php
// A third sidebar for widgets
if ( is_active_sidebar('third-widget-area') && !is_page(640) ) : ?>
<div id="third" class="widget-area" role="complementary">
<ul class="xoxo">
<?php dynamic_sidebar( 'third-widget-area' ); ?>
</ul>
</div>
You can also check page by it's name is_page('event-view')
try changing
if ( is_active_sidebar( 'third-widget-area' ) )
to
if ( is_active_sidebar( 'third-widget-area' ) && !is_page(640) )
this way you can check if the current page is any other than the one with the id 640; see http://codex.wordpress.org/Function_Reference/is_page
Try out this.
You can give pass page_id in is_page() function.
if(is_page('640') || is_page('49'))
And for more details see below.
http://wordpress.org/support/topic/display-widget-on-certain-pages
Related
Based on a particular value(appID) I want to hide one of the widget ID in my wordpress blog.
my widget Id : custom_html-2 ( I got this value from enabling accessibility mode)
( from this url I got widgetID : /wp-admin/widgets.php?widgets-access=on&_wpnonce=0b123456fb2&editwidget=custom_html-2&sidebar=right-sidebar&key=0 )
Here I want to hide custom_html-2 when the value of appID is in.abcd.app .
I just echoed appID , I am getting the value in.abcd.app , but the widget is not getting hidden.
I opened the Sidebar (sidebar.php) in the word press and did modification as bellow. Didnt workout - I am new to wordpress and PHP
<!-- Sidebar -->
<div class="col-lg-4 col-md-4 col-sm-4">
<aside class="sidebar">
<?php if ( is_active_sidebar( 'right-sidebar' ) ) : ?>
<div class="sidebar-widget">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
<?php
<?php $widgets = get_option('widget'.sidebar-widget); ?>
$appID = $_SERVER['HTTP_X_REQUESTED_WITH']
if ($appID = 'in.abcd.app')
{
<?php unset($widgets['custom_html-2']); ?>
?>
</div>
<?php endif; ?>
</aside>
</div>
<!-- /end sidebar -->
You'll want to add something like the following to your functions.php
add_filter( 'sidebars_widgets', 'unset_sidebar_widget' );
function unset_sidebar_widget( $sidebars_widgets ) {
$appID = $_SERVER['HTTP_X_REQUESTED_WITH'];
if ($appID = 'in.abcd.app')
{
unset($sidebars_widgets['custom_html-2']);
}
return $sidebars_widgets;
}
I suppose dynamic_sidebar( 'right-sidebar' ); renders the sidebar and the widgets, so if you unset a widget after the widget was rendered, it's not going to change anything.
Try to put the dynamic_sidebar( 'right-sidebar' ); after the unset part.
Im using the UnderScore theme and below is the main page.php template file. What im aiming for is if there is active widgets in the sidebar use template with sidebar but if no active widgets or content use template that has the main content as 960px with no sidebar. Im also using ACF (advance custom fields) is the sidebar so would need to check that aswell. Gratefull for any help. I thought maybe using "is_active_sidebar" but unsure how to implerment it properly as template parts are already being check.
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
Also below the sidebar.php
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
<?php the_field('sidebar_info'); ?>
</aside><!-- #secondary -->
Maybe I'm not fully understanding you question, but you can use a simple if-statement for that. See pseudo code below.
if ( active widgets in the sidebar ) {
// use this formatting
} else {
// use that formatting
}
I am looking for help to remove "junk" widgets from my wordpress website. Website theme is Zerif Lite and on every page so far there was no sidebar,however when I make a new post there is alot of junk (sidebar,who posted it,when,how entry was tagged and replay option).
I tried removing it from appearance->widgets and it didnt work and theme customization for widgets is locked for lite version.
So for start I 1st want to remove sidebar that include search,archives and meta.Only thing that worked so far was blanking out sidebar.php that include:
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h2 class="widget-title"><?php _e( 'Archives', 'zerif-lite' ); ?></h2>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h2 class="widget-title"><?php _e( 'Meta', 'zerif-lite' ); ?></h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; ?>
</div><!-- #secondary -->
However when I did that sidebar was removed,but space it took was blank,meaning post itself was only using 2/3 of page.
To get you to see for your self here are links to site (its in serbian,ignore that):
website and:
new post, this you can only see with this link,its where problem is
So if anyone can help me remove all that and make page clean I would be very greatfull. Thanks
The problem is css
Here is the solution (only if you dont use sidebar anywhere in your site)
Change the width of your content container, maybe right now is set to 70%(remaining 30% is for sidebar) to 100%.
If you plane to use sidebar, then you need set a conditional class in your functions.php:
function custom_body_classes( $classes ) {
// Adds a class of nosidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'nosidebar';
}
return $classes;
}
add_filter( 'body_class', 'custom_body_classes' );
Then only customize the css with the new class. Ex:
.content .nosidebar {
width:100%
}
Cheers
Stared a Wordpress site using Underscores theme (_s)
I have got one sidebar working but want to make a second one to be on the same page. (containing different widgets)
I have added the new sidebar to the functions.php and it appears in the Wordpress login screen and i can drop widgets into it. However, I can't get it to show on the actual webpage. (the first sidebar is working fine)
Anyone know how to do this or know a tutorial...
Thanks
You'll need to edit the "sidebar.php" file in your theme folder. It should normally be:
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
</div><!-- #secondary -->
You will need to add another if statement that looks out for the other sidebar. Be sure to reference it by whatever you used in the functions.php file.
If you want it to appear below the current sidebar, just be sure to add it before closing the 'div' so it will still be in the same column. I used 'sidebar-lower':
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
<?php if ( ! dynamic_sidebar( 'sidebar-lower' ) ) : ?>
<?php endif; // end sidebar-lower widget area ?>
</div><!-- #secondary -->
I am making a theme for my site which is WordPress based. I wanted a small help as I am not an expert on php. My issue is like this:
I have a side bar div which again within it has 4 sidebars:
<div id="jp-double-bar" class="equal">
<?php if ( is_active_sidebar( 'double-top' ) ) : ?>
<div class="jp-double-top">
<?php dynamic_sidebar( 'double-top' ); ?>
</div>
<?php endif; ?>
<div class="double-middle">
<?php if ( is_active_sidebar( 'middle-2' ) ) : ?>
<div class="jp-middle-2 equalmiddle">
<?php dynamic_sidebar( 'middle-2' ); ?>
</div>
<?php endif; ?>
<?php if ( is_active_sidebar( 'middle-1' ) ) : ?>
<div class="jp-middle-1 equalmiddle">
<?php dynamic_sidebar( 'middle-1' ); ?>
</div>
<?php endif; ?>
</div>
<?php if ( is_active_sidebar( 'double-bottom' ) ) : ?>
<div class="jp-double-bottom">
<?php dynamic_sidebar( 'double-bottom' ); ?>
</div>
<?php endif; ?>
</div>
Here my issue is that if I do not publish any widgets in any of the sidebars, still the outer <div id="jp-double-bar"> shows up.
My question is....... The way we are wrapping for individual sidebar with an <?php if ():?> statement, is there a way to wrap the main outer div with 4 if statements.
Like if there is no widget published in any of the 4 sidebars then the main outer div should not display at all.
Kindly help.
Regards
It seems that you have to be using the wp_get_sidebars api call to retrieve the bars. Check and see if this has a length of zero (empty).
Or just use and statements
if (is_active_sidebar( 'double-bottom' ) && is_active_sidebar('') && ...) {}