Conditional WordPress widgets with rich editable text

October 09th, 2007 – 1 Comment

For the “About Joost” widget shown on the homepage of this site, I created a new widget. It has two great features: it shows just on the homepage, and the content and title are drawn from a page, so that I can edit it as a normal page with the richtext editor in the backend of WordPress.

The code basically looks like this:

function widget_about_me($args) {
if (is_home()) {
while (have_posts()) : the_post();
echo $before_widget;
echo $before_title.get_the_title().$after_title;
echo $after_widget;

The is_home() makes sure the widget only shows up on the homepage, and then you enter into a new loop with a specific page id. After having done that, I open the “normal” loop again, to make sure other widgets and stuff that relies on is_home() keeps working.

Of course you have to make sure that you 301 redirect the “page” you’re using in the widget when it get’s opened directly to your homepage. There’s no reason for anyone to want to see just that content.

1 Response to Conditional WordPress widgets with rich editable text

  1. SEO Carly
    By SEO Carly on 10 October, 2007

    Thanks, very tricky i’m going to give this a shot. :)

    While we are on WP functionality, i’m just wondering if you had thought about or if there’s any particular reason you don’t have external links open in a new window?

    Often i click a link in your post to view what your referencing and close that tab.. and Joost is gone :-/

    You think i’d learn but hey, anythings likely to happen with me :-)

Check out our must read articles about Analytics