WordPress Text Widget Logic

The Widget Logic uses Conditional tags that controls where a widget should appear and conversely where it should not. We can write more than one conditional statements inside widget logic.

we’ll put our WordPress Conditional tags inside widget logic input filed as shown in figure.

Different Conditional statements syntax: 

 

[sourcecode language=”plain”]</span></div>
<div>
<div>

global $post;

</div>
<div></div>
<div>

if((is_page(‘page id’) || ($post->post_parent=="page id"))){

</div>
<div>

return (is_page(‘page id’) || ($post->post_parent=="page id"));

</div>
<div>

}

</div>
<div> <span style="font-family: Courier New;">[/sourcecode]


Display widget on page 

 

[sourcecode language=”plain”]</span></div>
<div>

is_front_page() : on front page.

</div>
<div>

is_home() : on home page.

</div>
<div>

is_page(‘page name’) : on given page name.

</div>
<div>

is_page(‘page id’) :on given page id.

</div>
<div>

is_page( array(‘abc’, ‘xyz’, 50, 75) ) : on array of multiple pages.

</div>
<div>

is_front_page() || is_page(‘xyz’) : on front page and xyz page

</div>
<div>

is_page(‘2715’) || ($post->post_parent=="2715") : on page id 2715 and its sub-pages.

</div>
<div> <span style="font-family: Courier New;">[/sourcecode]


Display widget on Post

 

[sourcecode language=”plain”]</span></div>
<div>

is_single(‘Abc’) : on given post name.

</div>
<div>

is_single(451) : on given post id.

</div>
<div>

is_single( array(‘ABC’, 45) ) : on array of multiple post name and id.

</div>
<div> <span style="font-family: Courier New;">[/sourcecode]


Display widget on Category

 

[sourcecode language=”plain”]</span></div>
<div>

in_category(‘abc’) : on given category name.

</div>
<div>

in_category( array(‘abc’, ‘xyx’, ‘Cat1’) ) : on array of multiple category.<span style="font-family: Courier New;">[/sourcecode]


Leave a Reply