WordPress Themes, Plugins, Tutorials, Tips And More...

Tag: Code

Best Of WordPress Code Snippet Part – 1

Programming-4

How To Completely Shut Down WordPress Search

Copy and paste the following snippet in your theme’s functions.php file and you are done.

Snippet Source/Credit: WPEngineer

How To Enlight Searched Text In Search Results

You do wish to Enlight searched text in your blog’s search results. To do so, simply open your theme’s search.php file and then find the the_title() function and replace it with:

And now just before the line you modified, add this code of lines:

Once done, now open style.css and append the following line to it:

Snippet Source/Credit: Yoast

Context Menus With HTML5

The following snippet below will give you an idea that what Context Menus with HTML5 actually is.

Snippet Source/Credit: Speckyboy

How To Make Your WordPress Website SEO Friendly Without A Plugin

This can be achieve by simply pasting the code in your theme’s functions.php file and you are done.

Snippet Source/Credit: Jeff Starr

Best CSS Code Snippet Websites

There is no doubt that one will be requiring code snippets to bring in some amazing piece of cake walk in the piece of work. Then, there is no matter whether that person will be a designer, a developer, a programmer or any other. Context to same thought, in this article, I have collected the best CSS Code Snippet websites for you.

Code And Me

CodeAndMe

[Visit]

Dev Snippets

Dev Snippets

[Visit]

Stack Overflow

StackOverflow

[Visit]

CSS Tricks

CSS-Tricks

[Visit]

Joyent

Joyent

[Visit]

Snipt

Snipt

[Visit]

HTML5 Snippets

HTML5 Snippets

[Visit]

CSS Pop

CSS Pop

[Visit]

Snipplr

Snipplr

[Visit]

Smipple

Smipple

[Visit]

WordPress Snippets – Part 1

Programming-4

How To Display Recent Posts From All Sites

The following snippet will display recent posts from all sites.

Snippet Source/Credit: Snipplr

How To Display Twitter Feed In WordPress

With an age of social media, it is very much important to display twitter feed in your WordPress website. Moreover, it is not only just for getting updates but also to encourage people more often with the tweets. To display twitter feed in WordPress, using the following snippet will let you achieve this.

Snippet Source/Credit: Smashing Magazine

How To Execute Shortcode From Custom Field

The snippet will let you add shortcode to a WordPress custom field while by default; the option is not available by WordPress.

Snippet Source/Credit: Leeboyce.co.uk

How To Generate Your Own Portfolio With Filtering Based On Taxonomy

Using the following snippet will let you generate your own portfolio with the help of filtering based on taxonomy.

Snippet Source/Credit: ToddWilson

How To Get An RSS Feed And Display Items With A Loop

Use of the following snippet will let you get an RSS feed and display items with a loop.

Snippet Source/Credit: DanGayle.com

How To Get Attachments For Post Or Page

Using the following snippet below will let you get attachments for posts or pages.

Snippet Source/Credit: Stack Overflow

Adding QR Codes In WordPress

QR Code

Thanks to the ways with which we have been enhancing with different things at pace which results in bringing a lot more substantial things into place. While for marketers, the question arises and still frightening their minds that whether the QR Code – Quick Response Code – are still there in use or they just get over.

It is quite even obvious that people not much aware about QR Code. Well, if in case, you too fall in same category, then to let you know that QR Code is a two dimensional matrix barcode which often being utilized by websites, virtual stores as well as online communities. It is basically as image with black squares, white background and dots in a square shape container. It is mainly seen by use for offering offer exclusive discounts, show special offers and more.

If you want to add such QR Code in your WordPress blog or site, then it’s better to go by easy and simple way by installing and activating a plugin which is suitable for the job. It name as QR Code Generator plugin. The plugin on installation will give you the freedom to use QR Code inside your post and pages with using the simple shortcode something like this:

Plugin In Use: QR Code Generator

The plugin will allow you to easily create a QR code on any site of your WordPress installation. The QR code contains the current URL or any other text you like.

How to use it:

  1. Use the shortcode [QRcode] within your site to generate a QR code including the URL of the current site
  2. Use the following short code to generate a individual QR code with any text content: [QRcode content=”CONTENT” size=”120″ alt=”ALT_TEXT”]
  3. Its not necessary to give any parameters!
  4. Possible parameters are: alt, size, class, credit, shadow
  5. If you dont give any parameter like ‘alt’ or ‘size’, the standard parameters are: alt = “Scan the QR Code” size = 120 class=”” credit = true shadow = true

More Info | Download

Photo Credit: Flickr/giaLLLO!

15 Useful WordPress Snippets

Developing a full fledge WordPress website and wondering on that a huge numbers of plugins you would be requiring to make it complete, don’t worry it can’t be a way all the time as there is Plan B also available which will help reduce your job: using WordPress snippets. Snippets are the short codes which you can use directly in your theme files – totally as per your requirement. Don’t worry also if in case you would be thinking that “hey, I am a WordPress beginner then what?” don’t worry on this as this short code requires very less of your technical knowledge – all important with it is the right placements of these codes in your theme files.

No Plugins Required

Page excerpt

The snippet will add excerpts for pages. All you require is to place the following code in your themes functions.php file and you are done.

Highlight author comments

Blog authors always want that their comments to look difference from that of the readers as it highlight and bring more values in reading. Using the snippet (below) will help you achieving the same. Find the list-item in the comment.php template file and add this in the class-tag.

Reset your password

This would be a biggest nightmare for you if not able to reset your password especially when you can’t use the “forgot password” function. Insert this snippet into a phpMyAdmin Sql-window.

Empty Trash Automatically

If you wish to have your WordPress trash to get empty automatically, then just add the following line of codes to the wp-config.php-file.

Image Custom Field

If you want to call the custom field for an image source, then use the following snippet.

Add Taxonomies

The snippet will allow you to create your own tag-section for your custom post types.

Remove meta generator

It would always be advisable to remove the “meta generator tag” which WordPress generates in your WordPress header. Use either of following code in your header.php template.

OR

Disable WordPress Update

To avoid client messing up with the whole of WordPress website, just add this to disable WordPress update function by adding this into your themes functions.php template.

Add a Dashboard Widget

As soon as you login into your WordPress Dashboard, the first thing you will notice that it has been filed with number of widgets. Using this code will allow you to add your own widgets, just add this code to functions.php.

Change footer-text in WP Admin

Using the code will change the text in the bottom of the WP admin pages.

Remove meta-boxes

Using this snippet, you can remove the meta-boxes you don’t use.

Enable debug mode

Add this to your wp-config.php and you will be able to debug your WordPress blog if something went wrong.

Change Admin logo

Give your Admin panel a brand look just like whole of your blog; change the logo in the Admin panel with an image of your choice by using this snippet.

Remove Pages Columns

The code will allow you to remove a column from pages.

Change role capabilities

WordPress comes with several pre-defined role capabilities, like Author, Contributor or Administrator. In order to change these, just add the following to functions.php and you can create your own and customized it as per you like.

Photo Credit: cogdogblog via photopin cc

21 Useful Snippets For WordPress

It’s being more than 4 years for me now to use WordPress and within all these years I worked on number of WordPress-based projects. While working on all these projects, I have been able to build up a pretty big collection of little snippets and tricks that helps me from time to time.

I’ve been added some new and old WordPress snippets to the sites while all the snippets I’ve been adding have been tested with the WordPress 3.5+ version. Based on all the experimentations I did, you will find the collection of best 21 useful snippets that I used for mine WordPress websites.

Rich-Snippets

Remove URL from Comment Form

It often happens that you don’t want to include the URL field in the WordPress comment form and at that time you would be requiring a snippet which helps you out to turn it off. You have to add the following snippet in the function.php of your theme.

Display a Random Post

The snippet will show a random post on your website. All you have to do is to add the following snippet in your template where you want it to appear.

Customize the Default Avatar

If you want to use a customized default avatar instead of using the standard WordPress one, all you need to do is to place the following snippet in the functions.php in your theme.

Create a Custom Post Template

Many of you don’t know that you do have an option to create custom page templates, although you can’t by default create templates for your posts. In order to make this happen, you have to download the Single Post Template plugin, which in turn will enable the ability to add post templates.

Once done, you have to make a copy of the single.php file of your theme and give it a new name that you want to keep it (say for example, “example.php”). Keep the file in the same location where you saved single.php. Now to create a custom post template, just copy the following snippet to the top of the page and you are done. Make sure that you have save it and it will be with the other files in the root of your theme directory. Now all you have to do is to go into the WordPress admin, edit a post and you will see a dropdown from where you can specify a post template.

Limit Number of Post Revisions

WordPress having the authority itself to keep the record of all the revision you have made to a page or post. If you are a person who is in practice of having hundreds of revisions per page or post, then this particular snippet is something that you definitely require. The snippet will limit number of post revisions. All you have to do is to put up the following snippets in the wp-config.php file in the root directory of your website.

Temporary Maintenance

The purpose of using the snippet is that you can temporarily close down your site for visits while your website can still be accessed by admins, which let you do the changes that you are planning for. In order to make your website live again for visitors, all you have to do is simply delete the function or comment it out.

Add featured images to WordPress feeds

The functionality to add featured images to WordPress feeds still not offered by WordPress itself, but in order to have this with you, you need to add featured images to your feed by adding the following snippet to your functions.php template.

Set Minimal Comment Limit In WordPress

A comment can either make your blog or break it out in front of your visitors as getting a good response is really valuable but a poor quality comment like “Great Post”, “Thanks” or just a smiley will harm your reputation. In order to avoid this or to stop on making such things happen, simply change the value of the $minimalCommentLength string to the minimum number of characters you require for each comment to your functions.php template.

Allow PHP in WordPress Text Widgets

Although the default text widget in WordPress only allows text but in order to add PHP inside your widget, you need to add this function to your functions.php template.

Redirect your Author archive link to your “About” page

If there are many authors on your website, then it would be very much required for you to redirect your author archive link to your “About” page and in order to make this happen, all you have to do is to add this little snippet to your functions.php template.

Change Image Path Only

In order to speed up the loading time of your website pages, you do often host the images on an external content delivery services. To help you with this, all you need to perform two SQL queries on your database which can do the complete job for you in a go.

Add Thumbnails in Manage Posts/Pages List

To display the corresponding thumbnail at the time when you browse posts and pages through you admin area, you need to add the following snippet to the functions.php template.

Checks if the visitor is from mobile device

The purpose to add this function is that to check if the user is visiting using a mobile device and returns result in true or false. To avail this function, you need to add the snippet to your functions.php template.

Add titles to previous_post_link & next_post_link

If you are using previous and next links on your articles, then this little snippet will be a perfect thing for you. It will add titles to previous post links and next post links in your article, which encourages more visitors to check on your content.

Disable Plugin Updates

If there is any updates for your plugins, and if it’s irritating you a lot, then this snippet simply prevents WordPress from checking it. This snippet could be useful especially if you are working on client’s website.

List all categories with posts

To have this function work for you, you need to add this to the template where you want the list to appear.

Override WordPress and Site URL

The snippet will allow you to redefine two constraints which make it possible for you to work with production databases, locally. The function does not change the database records or something although also there is no need to search and replace a whole lot of data in SQL. In short it lets you use the same database for production and development.

Get the first link in post

The time when you are using the new post formats, you will find the link type. It should be a post which has the intention to link to something other, instead of providing a lot of content. The snippet will allow you to find that first link in the post and will return back to you by which you can link the title to that place again.

Check if sidebar has widgets

The snippets checks that if a sidebar of your website having any widget areas in it or not.

Author Bio Excerpt

You want to show the author bio in your blog but instead of showing the complete bio, you want it short. This snippet will make an excerpt of the bio, which includes a link to the author page, where you can display the full author bio. All you have to do is to add the snippet to the functions.php template.

Disable Self Trackbacks

The WordPress trackback system will let you have a link back to your blog when other put up your content. But, the problem comes at a place when you link to one of your own posts, on your own website and a trackback will be displayed with the link coming from you. To avoid this, just simply put the snippet in functions.php.

Page 3 of 3

Powered by WordPress & Theme by Anders Norén