Tag Archive for wordpress

WordPress GG Twitter Widget

** Update July 12, 2013 **

I’ve updated this plugin to work with the new authenticated Twitter API.  Huge shout out to MatthewRuddy, author of Display Tweets. His code really helped me to get this working.

If you’re not running at least version 1.2.1, go get the update!

So I finally got around to officially releasing my first WordPress plugins.  The first one, which I’ve actually been using for a long time on sites I build, is GG Twitter.  The issue that I was having with off-the-shelf Twitter plugins was that they would just display an error message when they couldn’t connect to Twitter.  So mine stores the last known good tweet retrieval and displays that if a connection error occurs.  Mini-caching if you will.

I’ve also added various options to it that I haven’t seen in other Twitter widgets (though, really, I haven’t looked at that many of them).  So let me explain them in a little more detail.

Grinning Gecko Twitter Widget

Admin configuration screenshot for Grinning Gecko Twitter Widget.

Title:  This should be pretty self-explanatory.  The title that appears at the top of the widget.

Twitter Username:  Also pretty self-explanatory.  No `@` necessary.

Max Tweets to Display:  I’m noticing a trend here.  Self-explanatory.  How many tweets do you want to show in the list?

HTML for the View All Link:  This is the HTML (or just text) that will appear at the bottom of the tweet list linking to your Twitter page.  By default it just says “View All Tweets”.

Time Placement:  Lets you display the time of the tweet before or after the tweet itself.

Time Format:  Lets you format the timestamp any way you want, assuming you can decipher the PHP: date reference page.  The default format is Tue Nov 6th (as an example).  Putting something like `l, F jS @ g:i a` would display Tuesday, November 6th @ 1:30 pm.

Title Links To:  That’s the second plugin I just released.  More on that later.

I also wrap pretty much every element in its own class, so styling is easy without any hackery.

Download GG Twitter from WordPress.org

Fork GG Twitter on BitBucket

Hooking into Widget Delete Action in WordPress

The title of this post is technically a lie, since there is no widget delete action (that I’m aware of anyway).  However if you want to hook into the action that occurs when a widget is deleted you can use the following code in your functions.php :

add_action( 'sidebar_admin_setup', 'my_sidebar_admin_setup' );

function my_sidebar_admin_setup() {

     if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) {

          $widget_id = $_POST['widget-id'];

          if ( isset( $_POST['delete_widget'] ) ) {
               if ( 1 === (int) $_POST['delete_widget'] ) {
                    // Widget deleted; do something



The ‘sidebar_admin_setup’  action gets triggered, seemingly, anytime a change occurs on the Widget screen.  Dragging a widget, saving a widget, deleting a widget – all of these trigger this action.  It’s a pretty handy hook to know.

Overriding the Default Search Form

WordPress LogoI’m working on building an HTML5 WordPress theme that I’ll use as a foundation for all my projects. I’m sort of taking the shoot-first, ask-questions-later approach. That is, I’m using as much HTML5 goodness as I can, and I’ll deal with backwards compatibility later. So, I wanted to use a proper HTML5 search input.

In order to override the default search form, all you have to do is create a file called searchform.php in the root of your theme’s directory. WordPress will pick this up and use it. For reference, my form looks like this:

<form role="search" method="get" id="searchform" action="<?php bloginfo( 'wpurl' ); ?>">
<input type="search" value="" name="s" id="s" results="5" autosave="gg_search" placeholder="Search..." />
<input type="submit" id="searchsubmit" value="Search" />

Get Page ID of Posts Page

WordPress LogoYet another of those “it took me forever to find the answer so I figured I’d post it” posts.

The common answer to the question of “how do I get the ID of the current page?” is


But that fails when the page ID you’re looking for is actually the Posts page. In that case the above statement returns the ID of the first post, not the page itself. Really annoying.