Create a PDF viewer Shortcode

If you’re using PDF files on your WordPress blog, it could be very cool to give your users the chance to open them using Google Docs. The following recipe will show you how you can do that. The first step is to paste the following code into your functions.php file: function pdflink($attr, $content) { return […]

Read More

Allow upload of more file types

WordPress uploader won’t let you upload some filetypes. If you need to upload other file types this will allow you to do it. Paste the code in functions.php file. If needed, you can add more file types by adding them on line 4, separated by a pipe (|) <?php function addUploadMimes($mimes) { $mimes = array_merge($mimes, […]

Read More

Detect mobile visitors

First have to get the code from detectmobilebrowsers.mobi and upload it to your theme directory. Once done, simply open your header.php file and place the following at the top of the file. Don’t forget to edit line 5 according to the page where you’d like to redirect mobile users. include(‘mobile_device_detect.php’); $mobile = mobile_device_detect(); if ($mobile==true) […]

Read More

Show the number of results found

Search results pages are important for a website UX, so it should be pretty useful to the user. Problem is many search results page give no information about how many pages on what I’m searching for there are in a website. Thanks to the following line of code in your search.php file, you’ll be able […]

Read More

Change the post auto-save interval

The auto-save feature is your safety net: automagically WordPress saves your work, so you don’t have to worry about it in the event of a browser crash or a blackout. For some users though, the 1 minute default could be a little too much and they keep interrupting their work to push the save button. […]

Read More

Move Your WP-Content Folders

The wp-content folder contains your themes, plugins and uploads. Certain plugins, such as caching plugins, also use the wp-content folder to store data. Due to this, the wp-content folder is frequently a target for hackers, particularly those that insert malware into your theme files. You can make it difficult for people to find your wp-content […]

Read More

Truncate Post Title

The following snippet controls the maximum title length. Add the following snippet in functions.php. Then use the function customTitle() in the template to output the title in place of the WordPress the_title() method. function customTitle($limit) { $title = get_the_title($post->ID); if(strlen($title) > $limit) { $title = substr($title, 0, $limit) . ‘…’; } echo $title; }

Read More

Display PHP on a Single Page

Allows you to display plugins and such on a single page (replace home with the page you want it to only appear on): if ( is_home() ) { include (‘file.php’); }

Read More

Display Categories

Display Categories wp_list_cats(‘sort_column=name’); Display Categories in Drop-Down Box <form action=”<?php bloginfo(‘url’); ?>/” method=”get”> $select = wp_dropdown_categories(‘show_option_none=Select category&show_count=1&orderby=name&echo=0′); $select = preg_replace(“#<select([^>]*)>#”, “<select$1 onchange=’return this.form.submit()’>”, $select); echo $select; <noscript> <input type=”submit” value=”View” /></noscript> </form>

Read More