$(document).ready(function() { $(‘a[href*=#]’).click(function() { if (location.pathname.replace(/^//,”) == this.pathname.replace(/^//,”) && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $(‘[name=’ + this.hash.slice(1) +‘]’); if ($target.length) { var targetOffset = $target.offset().top; $(‘html,body’) .animate({scrollTop: targetOffset}, 900); return false; } } }); // how to use // place this […]
Category: 2015
HTML5 Data Attributes
HTML5 data attributes are a simple means to embed data in a webpage. It is useful for exchanging data between the server and the front end, something that used to require outputting <script> blocks or hidden markup. With the recent updates to the jQuery data() method, HTML5 data attributes are pulled automatically and are available […]
Latest Version of jQuery
With all the innovation taking place in the jQuery project, one of the easiest ways to improve the performance of your web site is to simply use the latest version of jQuery. Every release of the library introduces optimizations and bug fixes, and most of the time upgrading involves only changing a script tag. You […]
Use CSS Hooks
The CSS hooks API was introduced to give developers the ability to get and set particular CSS values. Using it, you can hide browser specific implementations and expose a unified interface for accessing particular properties. $.cssHooks[‘borderRadius’] = { get: function(elem, computed, extra){ // Depending on the browser, read the value of // -moz-border-radius, -webkit-border-radius or […]
Kitchen Sink 2
Custom CSS for the login page Create wp-login.css in your theme folder function wpfme_loginCSS() { echo ”; } add_action(‘login_head’, ‘wpfme_loginCSS’); function wpfme_has_sidebar($classes) { if (is_active_sidebar(‘sidebar’)) { // add ‘class-name’ to the $classes array $classes[] = ‘has_sidebar’; } // return the $classes array return $classes; } add_filter(‘body_class’,’wpfme_has_sidebar’); Call Googles HTML5 Shim, but only for users on […]
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 […]
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, […]
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) […]
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 […]
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. […]