Tip: add a widget anywhere with the_widget()

February 28, 2011 | No Comments Yet

Here’s a very useful tip for everyone comfortable with customizing their WordPress themes: you can add any widget anywhere on your site, not just in your sidebar or widgetized areas, using the template tag the_widget.

Here’s the syntax:

<?php the_widget($widget, $instance, $args); ?>

This post by Shailan explains how to find the widget class name and arguments to use in the code. Refer to the Codex for the names of the default widgets. Want to create your own widget? Valums shows you how.

Leave a Comment | Tags: , , , , , ,

Customize Acceptable Upload File Types

February 21, 2011 | No Comments Yet

WordPress Garage points out that there’s a limited list of allowed file types that you can upload via the WP admin. For certain custom sites, since WordPress is being used for everything these days, that may need to be modified and Chris Meller shows us how.

As of WordPress 2.2, there are 35 allowed file types configured in the default install. While there’s no admin-based tool for editing this list (nor any plugins that I’m aware of), it’s not at all difficult to add your own…

The idea is to add a custom function inside your theme’s functions.php to be used as a filter. In that function you can then add specific file extensions and their corresponding mime types. On the other hand, to remove a file type that’s allowed by default, use the function unset().

Sounds simple and painless! Of course, keep in mind that limitations are put in place to keep WordPress secure, so tread carefully. Also, for reference, there’s a list of the accepted filetypes at the WordPress.com Support section, but that may vary on a self-hosted install.

Leave a Comment | Tags: , , , , , , , , ,

15 snippets for functions.php

January 3, 2011 | No Comments Yet

You don’t need to buy the book Digging Into WordPress to get a hold of this essential list of custom functions for your functions.php file. There are a ton of things you can do with a tricked out functions.php, letting you forgo plugins and completely avoid hacking the backend code. From controlling excerpt lengths to loading scripts to customizing the admin, everything’s practically in there.

Perhaps one important thing to remember here is that the functions.php is located in the currently active theme folder, so if you like changing up your blog’s look quite often, don’t forget to bring the custom functions along. You can download the complete functions.php file at the end of the post.

Leave a Comment | Tags: , , , ,

Tip: use shortcodes anywhere

October 15, 2010 | No Comments Yet

Shortcodes are meant to be used for post and page content, but with a little custom code you can make them work elsewhere, as shown in this article:

  • Text Widgets
  • Template Files
  • Comments
  • Excerpts
  • User Descriptions
  • Category, Tag, and Taxonomy Descriptions

I think the most crucial piece of code to remember here is the one for theme files. Just add the line do_shortcode('[foo]'); and that will obey shortcode syntax. Super convenient! Also check out this list of custom shortcodes. For WordPress.com users, there are a bunch of media shortcodes already built in.

See also: how to use widgets anywhere.

Leave a Comment | Tags: , , , , ,

WordPress .htaccess tips

October 8, 2010 | No Comments Yet

Controlling how URLs behave and who access your site rely on the .htaccess file, and while some of the things it can do have a comfortable interface inside WordPress, there’s so much more to explore. WP Shout goes from A to Z of those possibilities.

For example: if you need to stop spambots, try denying no-referrer requests with this code:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Need to study the somewhat cryptic .htaccess language further? Head over to Apache’s official documentation.

Leave a Comment | Tags: , , , , , , , , ,

Count your feed subscribers for blog contests

August 10, 2010 | No Comments Yet

Let’s not ask why subscribing to one’s blog is a common criterion for all the blog contests out there; let’s be thankful Thaya Kareeson over at Weblog Tools Collection has written a helpful tutorial for keeping track of new subscribers to your RSS feed.

The technique involves adding a special contest code that appears only in the feed, which subscribers can use to indicate they are indeed subscribed:

A known solution to this problem is to include a special contest code into your RSS feed and not have this code visible on your website. That way each contestant will be forced to grab the code from your feed and submit the code via comments to verify that they have subscribed to the RSS feed.

Even if you’re uncomfortable with editing PHP, all you have to do is copy the code given in the article and you should be good to go. All in all, this is a smart technique that should help you out for your next blog contest!

Leave a Comment | Tags: , , , , ,

wp-config.php code snippets for autosave, post revisions, trash settings

April 28, 2010 | No Comments Yet

These are useful lines of code modifying the default settings on post revisions and autosave intervals, which you can insert in your WordPress site’s wp-config.php file at the root folder.

define('AUTOSAVE_INTERVAL', 160 );

Explanation: Set the length between autosaves to 160 seconds.

define('WP_POST_REVISIONS', false );

Explanation: Disable post revisions completely.

define('WP_POST_REVISIONS', 3);

Explanation: Limit the number of post revisions to 3. (Tip: install Revision Diet so you don’t need to do this manually, and you can also delete excess revisions created beforehand.)

define('EMPTY_TRASH_DAYS', 0 );

Explanation: Disable the Trash functionality completely.

define('EMPTY_TRASH_DAYS', 30 );

Explanation: Set the number of days between the contents of the WordPress Trash bin are completely deleted—posts, pages, comments, etc. This will be done automatically and without confirmation.

Even more snippets can be found at the Codex. Though I hope that in the future, WordPress can integrate these as configurable settings in the admin interface.

Leave a Comment | Tags: , , , , , , ,

A look at WordPress 3.0 custom post types

March 25, 2010 | No Comments Yet

kovshenin.com discusses one of the many new features coming in WordPress 3.0 that will raise its bar as a publishing platform: custom post types.

So what else could be done with WordPress’ Custom Post Types? Well, basically anything. Say you run an online store which of course has some static Pages (such as Contact, About, etc), some blog Posts, cause we’re so 2.0, remember? And Products, which would be a custom post type that contains the product name, description, product price, stock availability, and could even contain inquiries in forms of user comments!

He covers two key code snippets that gets the ball rolling on custom post types: register_post_type (WPEngineer has a great post on it) and custom functions for the edit post screen columns, which are added via a filter and an action:

The action outputs custom columns depending on the type, while the filter simply defines the columns for the Podcasts post type. It’s as simple as that. Note that I trimmed the code a little bit to fit on screen, so you shouldn’t be simply outputing 63:50, but actually count the podcast length 😉

Looks quite simple for those who know their way around PHP, but I expect plugins (and perhaps future releases of WordPress) to integrate interfaces for setting up and customizing post types.

Leave a Comment | Tags: , , , , , , , ,

WordPress Plugin: Favorites Menu Manager

March 12, 2010 | No Comments Yet

Favorites Menu Manager lets you customize the drop-down menu located at the top right of the WordPress admin screen.

Favorites Menu Manager allows you unfettered customization of that dropdown menu. You can easily add your own links, remove existing ones, and put them in the order you desire. Customizations are stored on a per-user basis, so each user can have their own collection of frequently used links.

You can also customize the Favorites Menu with code depending on which page is loaded in the admin panel, but doing so using a plugin is of course more convenient.

Download Favorites Menu Manager

Leave a Comment | Tags: , , ,

24 days of WordPress during the holidays

December 8, 2009 | No Comments Yet

The lovely folks at WPEngineer have started a WP Advent Calendar—a WordPress-themed countdown of sorts in line with the holiday season. It’s like 24 ways but for WordPress, or perhaps a winter counterpart to Summer of Code.

Here’s something from Day 3:

Imagine that it is possible to break into the blog, or potentially damage the entire web space of the server. I wouldn’t like to pay the invoice of your provider for the damage and surely don’t want to lose my whole website and files. And all this because you wanted to save $59!

If you want to have a special theme, buy it! The theme developer also provide support within the $59, also many developer help with customization, updates and much more. A pretty good deal in my opinion.

So take the advice and rather buy a premium theme than download it for “free” somewhere else. The same applies also for premium Plugins.

What a great way to spend Christmas, if I do say so myself!

Leave a Comment | Tags: , , , , , , , ,

WordPress Plugin: My Snippets

December 7, 2009 | No Comments Yet

My Snippets lets you add custom widgets depending on the post displayed. It adds a custom meta box where you can add text or code, which shows up in your widget areas.

What I wanted was something that allowed me to control widget content from the post editor, so I wouldn’t have to worry about setting my widgets. This gave me the idea for the My Snippets plugin.

What this plugin does is add an extra meta box on the post editor that allows you to input custom content. This content is then displayed using the Snippet widget in any widget area you choose.

This is a really neat idea for making your website more dynamic. Combined with a theme that has lots of widgetized areas, this could very well change the way people compose and add extra information like videos, graphs, or quotes to their blog posts.

Question is, would it be possible to add the meta content to your feed? Because RSS readers certainly shouldn’t be exempt from them. Or perhaps create shortcodes for inserting them into the post editor, but only make them appear in-text if it’s in the feed, and in the widget areas otherwise. Just a suggestion though! There are probably many other uses for this plugin that people can come up with.

Download My Snippets

Leave a Comment | Tags: , , , ,

Create your own WordPress Dashboard Widgets

June 26, 2009 | No Comments Yet

Did you know that you can tweak your WordPress Dashboard with custom Widgets? Take note that this is different from the Widgets feature you can use on your blog. WooCamp has a nice two-step tutorial on it:

  1. Copy the given code in the blog post
  2. Modify the given code for specific functionality for your widget

Easy-peasy! Another great way to customize the backend of WordPress-powered sites, especially if you’re using it as a CMS for clients and friends.

Leave a Comment | Tags: , , , , ,

Force WordPress theme CSS changes immediately

May 5, 2009 | 2 Comments

Theme authors: if you’ve been tweaking a WordPress site’s CSS file, the changes you’ve made usually don’t immediately show up for the blog visitors without a forced refresh. The reason: web browsers usually keep cached copies of site files. Mark Jaquith has a neat fix that allows you to grab the latest version of the CSS file and override the cached one automatically.

Just use this line of code in your header.php file:

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css?v=<?php echo filemtime(TEMPLATEPATH . '/style.css'); ?>" type="text/css" media="screen, projection" />

This automatically updates the ?v= part every time you modify the file. Boom. Now everyone instantly sees your changes.

This should also work for other files like your Javascript files.

Leave a Comment | Tags: , , , , ,

Beautiful and SEO-friendly titles for WordPress

April 7, 2009 | No Comments Yet

Even without transforming a WordPress-powered site into a full-blown CMS, there are a lot of sections to a WP site, e.g., posts, monthly archives, search results, static pages, and so on. One thing that helps keep visitors from getting lost when they dig deeper into these sections is knowing exactly where they are, and that’s by the titles of pages.

Learn how to customize those section titles with the help of this tutorial. Not only does it make for a better user experience, it gives plus points in the search engine optimization department as well!

Leave a Comment | Tags: , , , ,

WordPress participates in Google Summer of Code 2009

March 31, 2009 | No Comments Yet

Once again WordPress is participating in the annual Google Summer of Code and is inviting everyone to help out in improving specific aspects of the blogging software as well as related projects like WPMU and BuddyPress.

You name it, we want you to propose it. It’s true, competition is fierce, but hey, if you’re already hacking WordPress, you’re ahead of the pack as far as we’re concerned. Applications are being accepted as of today, and the deadline is on April 3, 2009.

There’s also a list of mentors you can approach if you want to participate in the summer-long hacking. It also helps to check out the suggested ideas section of the website.

Sign up here. Visit the Google Summer of Code 2009 site for more details.

Leave a Comment | Tags: , , , , , , ,