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

Tag: Short Code Page 3 of 4

WordPress Snippets That You Don’t Want To Miss

Computer Program -4

NO Follow WordPress Tag Cloud

The following snippet will result in no following WordPress Tag cloud. All you have to do is to add the snippet to your theme’s functions.php.

Expire Protected Post Cookie With Session

You need to set the time of 0 in setcookie() to your theme’s functions.php template. Setting the time will let you forces the cookie to expire the session.

Source: Drew Jaynes

Display avatar for currently logged in user with get_avatar

The snippet will let you display the currently logged in users avatar in your theme.

Prevent access to wp-admin

Adding this snippet to your functions.php will redirect subscribers away from wp-admin to the home page.

Source: Flowdrops.com

Hide login errors

The code will disable the login errors that are displayed to users.

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.

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.

Image Custom Field

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

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.

Photo Credit: Flickr/hackNY.org 

Must Required WordPress Snippets

The Scheme Programming Bee

Prevent WordPress to compress your jpg images

Adding the following code to your functions.php file will let WordPress prevent to compress your jpg images.

Source: WP-Snippets

Embed a page into another page

Paste the code below within the loop. And you will be able to embed a page into another page.

Source: CSS Tricks

Add extra contact methods to user profiles

Just paste the following code into your function.php file and you will be able to add extra contact methods for your user profiles.

Source: TutsPlus

Use shortcodes in theme files

The following snippet will allow you to use shortcodes in theme files.

Source: WP Snippets

Speed up your blog by caching custom queries

Simply paste the following code where you need to execute a custom query to the database and you will be able to speed up your blog by caching custom queries.

Source: WordPress Codex

Show admin bar only for admins

Simply paste the following code into your functions.php file and you will be able to show admin bar only for admins.

Source: Jeff Starr

Display number of Facebook fans in full text

Simply paste the following code, where you want your Facebook fan count to be displayed.

Source: WP Snippets

Restrict user access to specific templates

Simply create a new page template and paste the following code and you will be able to restrict user access to specific templates.

Source: Kevin Chard

Photo Credit: Flickr/Jeff Dlouhy

10 Essential WordPress Snippets

Programming

Adding Shortcuts to WordPress toolbar

Adding the following short code into your functions.php file will let you add shortcuts to your WordPress toolbar.

Source: Jeff Starr

Display pingbacks/trackbacks count within admin post columns

Adding the following code in your functions.php file will let you display pingbacks/trackbacks count within admin post columns.

Source: InstantShift

Easily embed and share Github gists

Source: Robert O’Rourke

Create a custom database error page

You often noticed the error “Error establishing a database connection.” Well the idea with this short code is to create a custom database error page. Copy and paste the code below in a new file name as db-error.php and save it on your wp-content directory and you are done.

Source: CSS Tricks

Add a “delete” button to WordPress admin bar

The following short code will let you add a “delete” button to WordPress admin bar. All you have to do is to copy and paste the code in your theme’s functions.php file.

Source: WPEngineer

Displaying RSS Feed

Adding the following code will let you display RSS feeds on your WordPress blog.

Source: Dan Gayle

Automatically create meta description from content

On pasting the following code into your functions.php file, it will let you create meta description from content automatically.

Source: Paul

Testing if a plugin is active or not

The following short code will let you track that whether the plugin is active or not.

Source: Cats Who Code

Change the “posts” label to “articles”

Open your functions.php file, paste the code and you will be able to change the “posts” label to “articles.”

Source: Smashing Magazine

WordPress pagination without plugins

Simply add the code to the place where you want to display your pagination and you are done.

Source: Smashing Magazine

Photo Credit: Flickr/mendhak

5 Useful WordPress Snippets

Programming

Display information about your multisite install

To display information about your multisite install, simply paste the following piece of code where you want the info to be display.

Source: Kevin Leary

Automatically remove p tags on images

Simply paste the following code on your theme functions.php file, save it, and the <p> tags are gone permanently.

Source: James

Automatically email guest authors when their posts are published

Copy the code below and paste it on your functions.php file and you will be able to automatically email contributors when their posts are published.

Source: Daniel Pataki

Create a login form shortcode

Paste the code below into your functions.php file which lets you create a login form shortcode for your WordPress blog.

Once done, add the following shortcode on the page where you want to have the login form added.

Source: DevPress

Reduce spam by using .htaccess

Simply paste the following lines into your .htaccess file but also make sure you do take the backup of the whole of your website before putting this shortcode.

Source: AllGuru.net

Photo Credit: Flickr/Mike Renlund

‘Must’ Required WordPress Snippets

While to help you out in numerous issues revolving all around your WordPress blog, there are hundreds of thousands of plugins available out there, but still what, one definitely need something more. If you have a little (fine) or intermediate (good) or an expert (perfect) knowledge of playing with codes, then the short codes (also known as snippets) will help you ease your job while dealing with issues surrounding your blog. In this article, we have collected such ‘must’ required WordPress snippets. Hope they will be useful for you.

Code

Prevent posts from a particular category to be displayed in WordPress loop

Often times come when you want to exclude certain category of posts from display on the WordPress loop. For excluding such categories, all you have to do is just copy and paste the code below into your functions.php file. But make sure you need to update the code with category ID you want to exclude on line 4.

Source: David Walsh

Search within a specific post type only

The following code will allow you to search only within a specific post type. Just copy and paste the snippet in your theme functions.php file and simply update the code with your post type name on line 4 and you are done.

Source: Hongkiat

Prevent WordPress from asking FTP credentials

Paste the following line in your wp-config.php file and you will be able to prevent WordPress from asking you yours site FTP credentials. The wp-config.php file is located in the root of your WordPress install.

Source: WP Tuts+

Secure your WordPress blog uploads directory

Adding the following code to your newly created file named .htaccess will let you secure your WordPress blog upload directory. The code will let only accept images files, while if in case you want to add any other file type, then make sure you add the file extension to the list on line 5.

Source: Jeff Starr

Easily get post content by ID

You often need to get the content or title from a specific post. The following code will display the content of the post with id $post_id.

Source: WordPress Codex

Display a custom message on WordPress registration page

You often like to display a custom message on your registration page. For doing this, all you have to do is paste the code below in your functions.php file with updating your message on line 6.

Source: Kevin Chard

Empty trash on a daily basis automatically

Simply open your wp-config.php file and add the following line of code and you will notice that WordPress automatically empty the trash on daily basis.

Photo Credit: Flickr/Lindsey Bieda

WordPress Snippets Collection Part – 3

Source Code

While we discussed and talked about different short codes available out there in our first and second part of this three-part series, today we are going to dig more deeper and will find more snippets – the short codes – which will help you ease your job more while handling different things in your WordPress blog.

Exclude specific categories from your blog homepage

There comes time often when you want to limit the numbers of categories to be on display on the homepage. For doing this, just copy the shortcode below in your functions.php file with replacing 5 and 34 – the category IDs – with the ones you want to exclude.

Source: WP Mayor

Redirect your author archive link to your “About” page

By default, on clicking on your author posts URL, a user gets redirected to your author archive page. It is useful on multi-author blogs, but when you are alone an author on the blog, it’s useless. Adding the shortcode below in your functions.php file will take your readers will take your users to “About” page but also make sure you do replace the slug you used for “About” page on line 4.

Source: WP Recipes

Prevent WordPress to display login errors

By default, when one fail to login on WP-Admin, WordPress displays an error message. It might works well for you as a blog owner but it gives a progress track for hackers. With using the short code into your functions.php file, you will be able to prevent WordPress from displaying login errors.

Source: WP Tuts

Redirect WordPress frontend to the backend

Using the following short code will let you automatically redirect all the frontend part of the site to your WP-admin/login page. Just simply copy and paste the code in your theme’s header.php file.

Source: Vladimir Prelovac

Shortcode to display external files on your posts

Adding the following shortcode to your functions.php file will let you display external files such as text or image on your posts.

Once done, add the following shortcode and you are done:

Source: Vladimir Prelovac

Getting the first link in posts

Using the following snippet will allow you to link a post to somewhere else instead of providing content. Just copy and paste the code into your functions.php file and you are done.

Source: WP Snippets

Remove WordPress version number from pages and feeds

Using the shortcode in your theme’s functions.php file will let you remove WordPress version number from pages and feeds.

Source: Jeff Starr

Load jQuery in the footer

By default, WordPress loads the jQuery JavaScript framework at the top of your files, but using the following shortcode in your functions.php file, will let force WordPress to load jQuery in the theme footer.

Source: Dominik Schilling

Photo Credit: Flickr/Niels Heidenreich

WordPress Snippets Collection Part – 2

Programming

Short Codes – the way to solve small issues in your WordPress blog. While there are plenty of plugins available out there to help you out with numerous small and big WordPress roles but sometimes and sometimes even more often using the short codes will help you out more. In this article, we present the second part of three-part series of WordPress Snippets Collection.

Suggested Reading: WordPress Snippets Collection Part – 1

How to automatically insert a list of related articles below the post

Copy and paste the following code into the functions.php file and once you are done, open your single.php file and call the function using the second code below.

Code 1:

Code 2:

Source: WP Tuts

Adding nofollow attributes to all links in a specific category

Copy the code below and paste it on your functions.php file.

Source: Sagive

Automatically spam comments with a very long url

Adding the code to your functions.php file will automatically mark as spam all comments with an url longer than 50 chars.

Source: CSS Tricks

Translatable JavaScript strings on your WordPress theme

Simply paste the following code into your function.php file, where you generally enqueue scripts and styles.

Source: WP Theming

Adding SVG upload support to your WordPress blog

Simply add the code below to functions.php in your WordPress theme.

Source: dbushell

Create a directory within the uploads folder

Adding this code snippet on your functions.php file (or plugin file if you’re creating a plugin)

Source: WP Mayor

Display an author bio excerpt

Paste the following code into your functions.php file.

Source: SEO Review Tools

Detect a comments page

Adding the following code anywhere on your theme files will return true if you’re on a comment page.

Source: SEOMix

Force your WordPress blog to break out of frames

Just paste the code below into your functions.php file, save it, and you’re done.

Source: WP Mix

Redirect to post if search results only returns one post

Paste the following code snippet into your functions.php file.

Source: Paulund.co.uk

Display the author posts in the admin post list

Adding the code into your functions.php file will let authors only see their own posts in the admin post list.

Source: WP Snippets

To run the loop outside of WordPress

Paste the following code on any PHP file where you want to run your WordPress loop.

Source: CSS Tricks

Allow more HTML tags in WordPress comments

Simply paste the following code in your functions.php file.

Source: David Walsh

Function to show a total share counter (FB, Twitter, G+)

Simply paste the following function where you want your counter to appear.

Source: Gleenk

Photo Credit: Flickr/Chris Hsia

Note: Like the post, then make sure you do follow and like us on both Twitter and Facebook.

WordPress Snippets Collection Part – 1

Code

While there are 26,410 plugins available in WordPress plugins respiratory which have been downloaded 500,583,147 times and even still counting, but still what you in seek of from time to time is some short codes – snippets – which by adding your theme files will give the desired result. These short codes can be of anything, depends in particularly that what you are planning to achieve by this. To ease your job of finding the right “required” snippet for your WordPress site, we have collected the best those snippets for you. We have divided the article in three-part series so that you can have all in your collection equally.

To check if the current post is a custom post type

Simply paste the code into your functions.php file and you will be able to check that if the current post is a custom post type or not.

While add the function can be used outside the loop:

Source: Snipplr

View all WP query variables

On pasting the code below on any files, you will be able to display the WP Query variables.

Source: WP-Mix

Conditional tag for blog-related pages

Adding the code into your functions.php template will let you know that whether you are on blog-related pages or not.

Source: ClickNathan

Automatically remove short words from the URL

Adding the code into your functions.php file will let WordPress automatically remove short (less than 3 characters) words from the generated permalink.

Source: WPSnipp

Check whether a plugin is active

Adding the short code in your theme file will let you check whether a plugin is active or not.

Source: WPMayor

Force specific pages to be SSL secure

Just add the following article to the functions.php file of your WordPress theme and specify the post or page ID desired.

Source: WPSnipp

Crop uploaded images

Add the code below to your functions.php file will let you crop uploaded images.

Source: WP-Snippet

Setting up different admin and theme languages

Simply set the desired locale followed by adding the code to your functions.php file.

Source: WP-Snippet

Using WordPress Shortcodes In Theme Files

To use a shortcode in a theme file, simply use the do_shortcode() function.

Linking Twitter usernames in WordPress

Simply add the short code in your functions.php template and it will let you automatically linked all twitter usernames in posts and comments to their Twitter profiles. Usernames have to be written under the form @username.

Source: Snipplr

Photo Credit: Flickr/Michael Himbeault

Note: Like the post, then make sure you do follow and like us on both Twitter and Facebook.

Best 20 ‘Must’ WordPress Snippets

There are times when the plugins will not be helping you out in providing you the solution which you are looking for in actual at that time if you know or having some useful snippets – the short code – with you – then you can complete the task easily by adding the code in your theme’s file. With this article, I showcased twenty “must” WordPress snippets.

WordPress

Add Contextual Help Tabs On Any Admin Page

The following snippet will let you create as many help tabs you would be requiring to switching the $screen_id.

Source: WP-Snippets.

Add Custom Image Sizes To Media Insert Dialog

The following snippet will add new image sizes to the Upload/Insert dialog in WordPress. You need to add the code to your functions.php file.

Source: WP-Snippets

Author Bio Excerpt

The following code will let you show a short intro of the author of a post instead of his complete bio.

Automatically Set The Featured Image

The snippet will automatically set the featured image by fetching out the post’s first image.

Check If Sidebar Has Widgets

The following snippet lets you check if a sidebar is having any widget areas into in it or not.

Check If The Visitor Is From Mobile Device

The snippet will let you see that whether your visitor is coming from mobile device or not.

Disable Plugin Updates

The snippet will disable on checking if there is any updates available for your plugins or not.

Finding The First Link In Post

The snippet will let you find the first link in the post and then returns back to you. Using this will allow you to link the title to this place.

Force Direct Update

The snippet will allow you to force direct update for WordPress or plugins. All you have to do is to insert the code into wp-config.php file.

Hide Toolbar When There’s An Error

You need to add the snippet in your functions.php file letting you hide toolbar when there is an error.

Include All Post Types In Search

The snippet will let you include all post types in search.

Override WordPress And Site URL

The snippet lets you override WordPress and site URL by redefining two constants which makes it possible for you to work with production databases.

Source: WP-Snippet

QR code With Article Link

Using the following snippet will let you rendered QR-code for every article.

Redirect User After Login

The snippet will let you redirect user after login. Just add this code to your theme’s functions.php file.

Remove Login Shake

Adding the snippet to functions.php file will let you remove the “wrong password” screen shake.

Remove WordPress Logo From Admin Bar

The following snippet will let you remove the WordPress logo on admin bar. You need to add the code to your functions.php file.

Set Featured Image Automatically

The following snippet will let you set featured image automatically.

Showing Admin Bar To Administrators

Add the code to your theme’s functions.php file to let you hide the admin bar to all logged in users except that of admins. A must for registrations-based sites.

Simple HTML In Widget Title

The snippet will allow you to easily use simple HTML tags in widget title area.

Truncate Post Title

Add this snippet into your functions.php file and whenever you are in need of truncating a title, just call the function.

Source: WP-Snippets

Photo Credit: Flickr/Phil Oakley

Useful Snippets For Password Protected Posts

WordPress Mug

We earlier discussed the manual way by which one can use password protection for WordPress posts, but one can also do the same by using the snippets, the short codes. The following article we will discuss all those snippets which can help you in keeping your posts or pages password protected.

Protecting Custom Fields

Unless and until the correct password is entered, WordPress does not show or display a password-protected post’s Content or Excerpt. But, you do also notice that the post’s Custom Field(s) data is not protected and can still be shown.

In order to make it stopped from displaying, you need to wrap your single.php or page.php files get_post_meta calls with adding a conditional statement using: post_password_required. You can also use the post_password_required function within in an if statement to do other customization.

Customized The Protected Text

Using short codes will also give you freedom to change the default text in the password form. You can change the default text for the password-protected post Excerpt by inserting the password form into the post Excerpt by using the following code in your WordPress functions.php file.

The password form basically displays the default message: “This post is password protected. To view it please enter your password below:” Using the snippet will return the form with different text and different html structure. Here do make sure that you don’t use print or echo function at all while using the snippet.

Protected Excerpt Text

Using the following short code will change the password excerpt text. The default Excerpt of a password-protected post is: “There is no excerpt because this is a protected post.” While after using the code will replace that text with the one you wanted. You are also allowed to use HTML here.

Add The Password Form To The Excerpt

You can also print out the password form instead of the Excerpt message. Using the following snippet will let you make the password form to be the Excerpt for a password protected post.

Hiding Password Protected Posts

You do often want to have your password protected posts to show up on different places in your site. You can use the following snippet in your theme’s functions.php file to hide the password protected posts from these pages without affecting your set pagination structure.

Photo Credit: Flickr/Carlos Varela

Page 3 of 4

Powered by WordPress & Theme by Anders Norén