Code Snippets

You can find useful code snippets in this section. We have collected huge amount of useful code to serve your needs. Also, if you have awesome tips to share, you can register now and start submitting and promoting your website.

Simple add / remove file upload box dynamically with jQuery

simple way to make a multi-file upload by adding or removing input tags easly bu MONGID DESIGNS

fillthis.jquery.js: a Generic form filler plugin

This plugin allows you to fill-up any form elements with a simple line of code You can pass all the fields value at once with a JSON object (check examples below) it's very useful if, for example you want to dynamically pre-fill your form from a server side scripts.

How to Create Random Image from Post Thumbnails WordPress
  • PHP
  • 08 Mar 12
  • 0
  • 812

WordPress provide feature to show your post randomly. You can find many tutorials talk about it. But, sometimes your emphasize in viewing images other than words. It happen when your sites talk about interior, artistic, photographic, or displaying products.

WordPress: Comment Count Shortcode
  • PHP
  • 14 Feb 12
  • 0
  • 2049

Use this shortcode to display a specific post’s comment count. All you have to do is add the post ID.

jQuery multiple ajax call

As ajax is async, if you or your user triggers the event too fast, it may cause multiple ajax call. Also if You wont to loop ajax calls, the solution to the issue is to queue your ajax call.

How to Hide a Part of WordPress Post or Page from Non-logged in Visitor
  • PHP
  • 31 Jul 11
  • 1
  • 2929

WordPress provide private feature to make your post or page only visible to other editors or site admin. Once a post is set to private, regular visitor won’t be able to read the post. Now, what a about if We want to hide only a part of the post? This code snippet will show You how to do it. Read More: http://www.dynamicwp.net/articles-and-tutorials/hide-a-part-of-wordpress-post-or-page/

Create a jQuery Random Filter

This simple and handy jQuery filter return a single random item from a selection of items. Credit to Waldek Mastykarz.

Changing WordPress Excerpt Length and Custom More Text
  • PHP
  • 19 Jul 11
  • 0
  • 6817

Most of the WordPress blogger uses excerpt to display a short summary of articles. This snippet able to let your control the length of excerpt, and make a custom more text after the excerpt. It uses add_filter with excerpt_length and excerpt_more. This snippet only work with excerpt generated by WordPress, not working with the optional excerpt field in the backend.

Add Google Analytic Code to WordPress Footer With add_action function
  • PHP
  • 19 Jul 11
  • 6
  • 4945

Simple snippet to add script to your WordPress template footer without having to add it into your footer.php. You can use this to append Google Analytic Code by using add_action function and append your script to wp_footer. It's a cleaner solution so your html file always separate from Javascript.

10 Useful Javascript Snippets for your mobile websites

After developing a few mobile websites in the past few months, I notice that I am reusing certain Javascript code in every project. Followings are the 10 Useful Javascript Snippets that I use for mobile sites. Note that some snippets require jQuery mobile framework.

4 Types of CSS Hacks for Web Designers and Developers
  • CSS
  • 15 Jun 11
  • 1
  • 4305

If you are a Web Designer or Developer and looking for a CSS hacks then this post going to help you. In this post I am going to share 4 different types of CSS hacks you can use.

How to Remove Links Tab from Admin Panel
  • PHP
  • 24 May 11
  • 0
  • 2899

WordPress admin interface has became more intuitive now. In the admin page, You can see the main navigation menu detailing each of the administrative functions you can perform, grouped in collapsible tabbed panels on the left-hand side column.

How to Get URL for Blog Page When Using Static Homepage
  • PHP
  • 17 May 11
  • 0
  • 3102

By default, a WordPress website displays the blog page, which is your most recent posts, on the front page. But many WordPress users want to have a static front page or splash page as the front page instead. Fortunately, WordPress allows you to select a different page for your home page

How to Display Posts only from Current User
  • PHP
  • 10 May 11
  • 0
  • 3029

When a contributor in a multi-user site see the post list in the admin page, he could see not only his posts, but also posts from other contributors. Even he couldn’t edit the other posts, this still could be a problem if there’s alot post already and he have to search from page to page to find his posts. How about displaying his post only? This snippet will show how to do it.

How to Display Specific Category Only In Search Result
  • PHP
  • 04 May 11
  • 0
  • 3263

While customizing a WordPress site, sometimes We also need to configure, how our WordPress site display the search result. On our previous code snippet, I have showed how to exclude specific category from search result. This tutorial will be the reserve, display the posts from specific category only in search result.

HTML Select Box with Country List

A list of countries in select box can come in handy when you're building a form. I was searching around for a few times now, I think it will be a really handy and good addition to my code repository.

How to Limit Character in The Post Title
  • PHP
  • 19 Apr 11
  • 0
  • 3184

Sometimes, You might want to automatically limit the length of post title in the main page. This little wordpress hack will allow you to limit the displayed post title by a defined number of characters on your blogs home page.

CSS Min-Height Hack
  • CSS
  • 18 Apr 11
  • 0
  • 4277

Internet explorer does't support min-height, but this CSS method will allow it.

Javascript Trim, Ltrim and Rtrim functions

This Javascript code trim implementation removes all leading and trailing occurrences of a set of characters specified. If no characters are specified it will trim whitespace characters from the beginning or end or both of the string.

How to Add Fancy JQuery Live Comment Preview to Comment Textarea without Plugin

The comment live preview feature helps the comment writer to see what they are writing in the comment form as they write. This feature works well to help prevent errors in spelling and grammar by giving the user a chance to see what they are writing before they post their comment.

How to Create Preload Images with jQuery in WordPress

In todays tutorial, we will learn how to preload the images with jquery. With this feature your site can enhancing user exprience.

How to List Categories along with Their Posts
  • PHP
  • 17 Mar 11
  • 0
  • 3275

To help site visitor finding one or two categories, We can use default widget or wp_list_categories to list the categories. In some case, We want to display the categories along with their posts. Unfortunately, this default widget and function can’t perform that. But this snippet can. Read more : http://www.dynamicwp.net/articles-and-tutorials/how-to-list-categories-along-with-their-posts/

CSS PNG Hack for IE6
  • CSS
  • 17 Mar 11
  • 1
  • 6094

A quick and non javascript PNG hack. Just put this in a ie6.css file, and apply the class to any div or img that using PNG images with transparency. It doesn't support background repeat.

How to Create Fancy JQuery Tooltip for Your WordPress Post Title

Usually, WordPress theme developer already provide a tooltip for post title. This tutorial, a very easy tutorial, will help you add a fancy jQuery tooltip for your WordPress post title, replacing the default one. Read more: http://www.dynamicwp.net/articles-and-tutorials/how-to-create-fancy-jquerytooltip-for-your-wordpress-post-title/

htacess redirect non-www to www or other way around

A simple htaccess code to redirect your website from www to non-www or vice versa. It's important concept in SEO because most of the search engine will treat www and non-www as separate website. As a result, you want all the traffics focus on a single domain name, thus, this htaccess code is a good snippet to know.

Backup and Restore Databases With MySQL Dump
  • SQL
  • 07 Mar 11
  • 0
  • 4419

This handy command line snippets allow us to import and export databases or tables with mysql built in function. Mysqldump command can be configured to export databases, or just a table.

How to Insert Code after More Tag within WordPress Post Page
  • PHP
  • 02 Mar 11
  • 0
  • 3646

This Simple tutorial will show you how to add/insert code or advertisement etc. right after the tag, but within the post page. For doing this, all we need is to add some piece of code in your theme’s Functions.php

How to Restrict a Specific Word from Post Title
  • PHP
  • 28 Feb 11
  • 0
  • 2868

This article shows simple usage of WordPress hook. The hook we are using here is post_publish, to restrict a specific word from post title. Read More: http://www.dynamicwp.net/articles-and-tutorials/how-to-restrict-a-specific-word-from-post-title/

A New CSS Clear Floats Hack
  • CSS
  • 22 Feb 11
  • 10
  • 6494

This clearfix hack is good to clearing floats without having to adding additional html tag. floating is quite a common technique to make a tableless layout, and it's really annoying how many times you have to create a div with clear float class in it. This hack will solve that problem, instead of creating a new div, you attach this class to the parent class. It works flawlessly.

How to Group Articles or Posts by Author
  • PHP
  • 21 Feb 11
  • 0
  • 2994

Grouping articles in specific criteria, like category, date or alphabet, could always help visitors to quickly find one or two posts. In my previous tutorial, I’ve shared a code snippet to group posts aphabetically. This time, I’ll share the code to group posts by their author. Read More: http://www.dynamicwp.net/articles-and-tutorials/how-to-group-articles-or-posts-by-author/