Posts tagged: functions

Remove Private/Protected from Post Titles
I had the situation come up where I need a password-protected post in WordPress. Of course that is super easy in WordPress, you can set up a password for it right in the “Publish” box before publishing. But by default, WordPress appends “Protected: ” to the front of the post title, before and after the password has been entered. I didn’t like that, and thought that the password box was clue enough that the material was password protected.

WordPress Tip: Remove nofollow Attributes from Post Content
If you have posts that include the nofollow
attribute on links, you may at some point decide to remove them. By default, WordPress doesn’t insert nofollow
attributes in post content, but there are a variety of plugins that will insert nofollow
into all links in post content.
Or perhaps you have been manually adding nofollow
tags to your post links for SEO purposes. Regardless of how they got there, it’s very easy to clean things up and remove all nofollow
attributes from post content.

Rounded Font-Sizes (with Colors!) for Tag Clouds
Tag clouds accomplish their varied font sizes by applying inline styling to each tag. The resulting font sizes can be really weird with values like font-size: 29.3947354754px;
.
Of course, there is nothing inherently wrong about that, but it feels a bit unsettling and less controllable. Awesomely, Mike Summers sent in a solution he uses on his own site..

Leave Comments Open Forever on Specific Categories or Page Templates
I like the idea of shutting off comments after a certain number of days. Here on Digging Into WordPress we do it after 90. After that kind of time, the “community” of the discussion is long over. I think a good practice for turning off comments is to instead leave a message informing visitors that the comment thread is closed, and offer a course of action in case they have something of grave importance to share. Here is an example from CSS-Tricks:

Custom Query Shortcode: Run a Loop inside Any Post/Page
I had the occasion yesterday to have a page with a section on it where it would output a very specific set of other pages, which would need to change dynamically. What I could have done is built a special page template for this page, and inside that template run a query_posts()
to get these posts. But I wanted this page to remain editable from the admin. Besides, creating a special page template every time you need to do something like this is too cumbersome. WordPress is extensible enough to do better.

Google Maps Shortcode
David Hollander of SparkWeb Interactive sent us in a little code clip for inserting Google Maps into Posts/Pages by the use of shortcodes. Google actually has copy-and-pastable iframe code already in Google Maps that is really easy to snag, but David was having problems with the Visual text editor screwing up the code when saving the Post. With a short code, no problem.

How to Disable Comment Feeds for Individual Posts
By default, WordPress generates an RSS feed for the comments on every published post. Many sites take advantage of this by displaying a feed link next to the comments area. This enables visitors to subscribe to the comment thread and stay current with conversation. It’s convenient, simple, and super useful. For example, a typical feed menu for many blogs includes the following items:

Rude Things Plugins Can Do
I heart plugin authors. Their work is generally amazing, a huge benefit to the community, the reason why WordPress rules so much, and deserving of much worship. That being said, plugins can do some pretty rude things sometimes…

Easy Shortcode Permalinks
When you are building a theme, and the circumstance comes up where you need to create a link to a specific page hard-baked right into the theme, there is a function you should be using.

Precision Targeting with Custom Action Hooks
WordPress’ powerful action-hook system makes it possible to insert functionality at any point in your theme. Most WordPress themes include some of the built-in WordPress hooks by default. For example, most of us are aware of the two most common WordPress hooks: wp_head()
and wp_footer()
, which generally appear in the theme’s header and footer sections. These two hooks provide WordPress a location at which to execute various scripts and functions. For example, the wp_head()
hook is where WordPress generates a variety of <link />
and <script></script>
elements, among other things.

Global Custom Fields, Take Two
Just as I hoped, someone wrote in with a far nicer solution to my Global Custom Fields solution than I originally had. Big thanks to David Hollander for this.

Global Custom Fields
Custom fields allow us to attach data to Posts or Pages that we can yank out and use at will in our templates. They are awesomely flexible and single-handedly allow WordPress to be used for about any CMS need. The fact that they can only be used on single Posts can be limiting in some circumstances. Sometimes you wish you could grab a custom value that you can control and is consistent globally, regardless of the current post. In this post we’ll look at a technique to do so.

Easy Custom Feeds in WordPress
Now that we have seen how to setup Tumblr-style posts, it would be nice to be able to segregate the Tumblr-posts category from the main feed into its own, separate feed. This would enable readers to subscribe exclusively to the Tumblr-posts feed and maybe display it in their sidebar or something.

How to Implement Tumblr-Style Links for Posts and Feeds
Since posting the DiW tutorial on designing a Tumblelog theme for WordPress, several readers have asked for a tutorial on how to setup just the Tumblr/tumblelog-style post links …without having to implement the entire theme.