Posts tagged: functions
There are many books and tutorials that share useful code snippets for WordPress. For example, you can find hundreds of custom functions right here at DigWP.com. You can also find them in my WordPress books, tutorials, and code snippets. For many code snippets and custom functions, the usage instructions will say something like:
In my recent post, DIY WordPress Popular Posts, I share a simple, two-step technique for tracking and displaying popular posts on your WordPress-powered site. That post describes everything needed to fully implement DIY popular posts, but some folks wanted an easier (more convenient) way to display the list of popular posts on the front-end (instead of using template code).
The WordPress Toolbar makes it easy for plugin and theme developers to add links and other items. This is great news if you find the added links useful; otherwise, the additional links may be more of a nuisance, cluttering up your current workflow. For example, the database-backup plugin UpdraftPlus adds an “UpdraftPlus” link. Some users probably think this is awesome, but for my own sites it’s just not necessary, and is something I would like to remove. So for this DigWP tutorial, we’ll use the UpdraftPlus Toolbar link to demonstrate how to remove unwanted items from the WordPress Toolbar in general.
Over at my code snippets site, I keep track of the most popular posts and display a list in the sidebar. It’s an easy way to highlight the site’s best content and share top snippets with visitors. There are numerous plugins available for displaying your site’s popular posts, but they tend to be overkill and/or employ weird algorithms that are just unnecessary and not always accurate.
For example, a lot of plugins and techniques calculate popular posts based on number of comments. These days I’m just not sure if that’s a relevant measure of popularity. Some sites have comments disabled, and other sites receive very few comments in general, so going the comment-count route just doesn’t work.
What I wanted was a simple way of counting hits and displaying a simple list of the most popular posts. This DigWP tutorial explains how to do it with two easy steps. Sound good? Let’s dig in..
After taking the time to set a whole bunch of theme options, it’s nice to be able to make a quick backup of your theme settings. Many themes have this functionality built-in, but for themes that don’t, here is a plug-n-play snippet to create a “Backup/Restore Theme Options” page. You can see the technique in action in my shapeSpace theme (100% free and open-source WordPress starter theme).
After updating to WordPress 3.8, the single-column Dashboard disappears with no options to bring it back. For years, users could set the number of columns in the Dashboard to suit their needs, but apparently some brilliant decision was made to just remove it. Personal opinions and feelings aside, here is a quick snippet to bring back single-column Dashboard layout for those who were using it and wish to continue doing so.
Most SEO plugins have way too many bells and whistles for my simple needs, so I wrote a little snippet that’s meant as a drop-in, DIY replacement for the big WordPress SEO plugins. If you want a lot of features and options, then try Yoast’s awesome SEO plugin or the great All in One SEO; otherwise, if you just want something simple that works, check out Basic WP SEO — a simple slab of code that you add to your functions.php file and done.
WordPress feeds enable your visitors to subscribe to your content for use in their favorite feed-reader. For example, subscribing to the main-posts feed and/or the comments feed is a great way for your readers to stay current with all the latest news and content from your website.
With WordPress, you can deliver a wide variety of “Full-text” or “Summary” (partial) feeds in numerous formats, including Atom, RDF, and RSS2. This variety extends the reach of your content by enabling your feeds to be read in more apps, readers, and devices.
WordPress makes it easy to add custom stuff to the Toolbar. This is a great way to personalize the look and feel of the WP Admin with custom menus, links, or whatever makes sense. To further streamline workflow, you can create keyboard-shortcuts to open your Toolbar links with a single keystroke.
Delivered on Google’s “world-class platform,” Google Analytics is a powerful way to monitor your site’s statistics. As flexible content-publishing software, WordPress provides a variety of ways to add Google Analytics (GA) to your web pages. These techniques range from including the GA tracking code directly to using plugins that are easy to customize from within the WP Admin area. In this DigWP post, we cover it all with 5+ ways to add Google Analytics to your WordPress-powered site.
Donkey work is really the last thing I want to be doing. Piddly tasks that could have been avoided with a little thought and perspective. In this DigWP tutorial, I explain how I worked my way away from becoming a donkey with a dozen child themes to manage and maintain, with just a little knowledge of a native WordPress function.
An easy way for visitors to enter their emails is by commenting on a post. We did this recently for people to sign up for a notification email. Instead of using a plugin or custom function for a one-time email list, we just went with WordPress core functionality and used post comments for people to sign up. Then the trick is retrieving the comment information from the database for the sign-up post.
A cool trick you can do with WordPress is display information directly from your theme’s
style.css stylesheet. I recently used this on a site where the theme’s version number is used throughout the template to keep things current and consistent.