TJ Singleton Software Engineer, Baptist Preacher

11May/100

WordPress Bug with Reading Settings, Front Page Displays

I came across a bug today where despite the fact the Reading settings were set to the latest posts, that the Front Page setting was still affecting the menu structure of wordpress.

Notice in the following images that "About" page is absent from the breadcrumbs, and is marked as excluded from the navigation.

The fix is simple. Just update the Front Page setting to the empty option and the menu correct hierarchy is restored.

Filed under: Wordpress No Comments
10May/100

Bulk deleting posts in WordPress

I was importing posts into wordpress and messed up. It's not uncommon. I normally have a couple failed attempts, before I get everything zeroed in with a new csv template.

I've learned my lesson in the past so I always set the post author to a distinct user to easily bulk delete posts based on the post_author with sql.

DELETE FROM wp_postmeta 
WHERE post_author = 50

However, this leaves trash in the wp_postmeta table so now we just clean that up by deleting everything without a entry in wp_posts.

DELETE FROM wp_postmeta
WHERE post_id NOT IN (
  SELECT id
  FROM wp_posts
)

Now that there is no trace of my failed attempt I can reprocess the file, hopefully successfully this time.

Filed under: Wordpress No Comments
28Apr/100

Remove the Genesis Favicon

remove_action('genesis_meta', 'genesis_load_favicon');
Filed under: Wordpress No Comments
9Apr/101

How to use shortcodes in widgets

Want to use shortcodes in your text widget? Just add this snippet to your functions file.

add_filter('widget_text', 'shortcode_widgets');
function shortcode_widgets($widget_text) {
  ob_start();
  do_shortcode($widget_text);
  $captured_content = ob_get_contents();
  ob_end_clean();
  return $captured_content;
}
Filed under: Wordpress 1 Comment
5Feb/100

Adding Cachable Javascript and CSS links to your WordPress Theme

Here is a great technique for adding a timestamp to your the javascript and css for your theme using enqueue_script and enqueue_style. The benefit is you can set a far future expires header and maximize the caching benefit without having to worry about cache invalidation. This technique should be familiar to any Rails devs as it's baked in.

The magic is that the one of the optional parameters of the enqueue_* functions is a version. We can use php's filemtime function to get the last modified time of the file as a timestamp and use it for the version. WordPress appends the version to the end of the url like "http://yoursite.com/wp-content/themes/your-theme/style.css?ver=1265429348". Now you don't have to worry about serving stale data since every time you edit the file the url will be updated.

Here is some example code:

  $stylesheet_url = get_bloginfo('stylesheet_url');
  $stylesheet_path = TEMPLATEPATH."/style.css";
  $stylesheet_mtime = filemtime($stylesheet_path);
  wp_enqueue_style("my_theme", $stylesheet_url, false, $stylesheet_mtime, "screen");
 
  $javascript_url = get_bloginfo('stylesheet_directory')."/my_theme.js";
  $javascript_path = TEMPLATEPATH."/my_theme.js";
  $javascript_mtime = filemtime($javascript_path);
  wp_enqueue_script('my_theme', $javascript_url, false, $javascript_mtime, true);
}
 
add_action('template_redirect', theme_assets);
Filed under: Wordpress No Comments