Skip to primary content
Skip to secondary content

Ken Judy

Trusted Adviser and Coach, Purpose-Oriented Leader

Ken  Judy

Main menu

  • Home
  • About Ken Judy
  • Book List
  • Contact
  • Technical Writing
  • Thanks

Tag Archives: blogroll site

How to make wordpress sidebars only appear on certain pages for search engine optimization

Posted on December 27, 2009 by Ken Judy

I was reading the recommendations in yoast.com’s post on wordpress seo.

Do you really need to link out to all your buddies in your blogroll site wide? Or is it perhaps wiser to just do that on your front page?

I want to link out on my homepage but I don’t need my sidebar to extend two screens below the content on my individual post pages.

So, it appears desirable to have elements of the sidebar (e.g. the blogroll and external social networking arcana) only appear on the homepage of my blog.

Thanks to some sample code from wpcandy.com, this was trivially easy to implement.

I modified the functions.php in my theme to register three sidebars. I called them Top Right Sidebar, Front Page Sidebar, and Bottom Right Sidebar.


if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Top Right Sidebar',
'before_widget' => '', // Removes <li>
'after_widget' => '', // Removes </li>
'before_title' => '<h2>',
'after_title' => '</h2>',
));

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Front Page Sidebar',
'before_widget' => '', // Removes <li>
'after_widget' => '', // Removes </li>
'before_title' => '<h2>',
'after_title' => '</h2>',
));

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Bottom Right Sidebar',
'before_widget' => '', // Removes <li>
'after_widget' => '', // Removes </li>
'before_title' => '<h2>',
'after_title' => '</h2>',
));

Then I modified my sidebar.php to render those three sidebars if the dynamic_sidebar function exists also making the Front Page Sidebar conditional on is_front_page().

<?php
if ( function_exists('dynamic_sidebar') && dynamic_sidebar('Top Right Sidebar') ) : else :
?>
//default markup for the top sidebar goes here
<?php endif; ?>
//renders only if the current page is the front page, i.e. is_front_page()
<?php if ( function_exists('dynamic_sidebar') &&
is_front_page() && dynamic_sidebar('Front Page Sidebar') ) {} ?>
<?php
if ( function_exists('dynamic_sidebar') && dynamic_sidebar('Bottom Right Sidebar') ) : else :
?>
//default markup for the bottom sidebar goes here
<?php endif; ?>

Wordpress Widget Admin PageIn my widgets admin I now have three sidebars listed:

  • They are defined in my theme’s functions.php.
  • They render stacked one on top of the other based on the markup in sidebar.php.
  • I can populate them in the widget admin.
  • The middle bar only appears on the homepage.
Posted in software development | Tagged blogroll site, external social networking arcana, php, search engine, search engine optimization, seo, widget, wordpress

Ken Judy

ken h. judy
I am an executive leader, software developer, father and husband trying to do more good than harm.
I am passionate about transforming teams and organizations through ethical thinking, agile values, and creative problem solving. I have published and presented peer-reviewed papers on these topics. I hold certifications in software development, scrum, and information privacy. I am committed to continuous learning and professional excellence. As a purpose-driven leader, I strive to create a positive impact for our clients, our people, and our planet.
IEEE CSDP
IEEE CSDP
Scrum Alliance CSP
Scrum Alliance CSP
IAPP CIPP/US
IAPP CIPP/US
Proudly powered by WordPress
 

Loading Comments...