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

Tag: Shortcode

Essential Snippets For Your WordPress Blog

Computer Program -1

Easy WordPress Drop Downs using CSS

The snippet will help you creating an easy WordPress drop downs using CSS.

Source: AmberWeinberg

Redirecting your homepage to the first post

Simply paste the code to your site’s homepage file (mainly it is index.php file) and you will be able to redirect your homepage to the first post.

Source: Ashton Sanders

How to automatically add a search field to your navigation menu

On copying the code to your theme’s functions.php file you will be able to add a search filed automatically to your navigation menu.

Source: Ronald

Removing the “read more” jump

Adding the shortcode into your functions.php file will remove the “read more” link from your blog which will automatically takes you to the article page.

Source: Alex Denning

Redirect feeds to a single format

Adding the following shortcode to your .htaccess file will let you direct all your feeds to a single format.

Source: Digging into WordPress

How to have a simpler WordPress login url

Adding the following code to your .htaccess file will let you have the simpler WordPress login url.

Source: Kevin Chard

WordPress is_child() and is_ancestor()

To use the following snippet, simply add it in your theme’s functions.php template.

Source: CodeByte

WP – Roles and Capabilities

The snippet will let you define different roles and capabilities.

Source: Snipplr

Clear out jquery to prevent conflicts

The snippet will let you either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.

Source: WordPress Codex

Photo Credit: Flickr/hackNY.org

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

Adding WordPress Widgets In Post And Page

There comes a condition in front of you many times when you wish that your favorite sidebar will get added to your post and page content. But the confusion over on this exactly will be the best bet to perform.

amr shortcode any widget

Starting with you need to install a plugin name amr shortcode any widget first and once activated go to Appearance >> Widgets. Once completing this task, now drag and drop the widgets you want to display in your post or page into the Shortcodes sidebar, followed by adding the shortcode [do_widget id=widgetid] in a page or post.

Plugin in use: amr shortcode any widget

The amr shortcode any widget is a simply “utility” plugin which allows you to have any widget used in a page shortcode in any theme.

Steps To Follow:

  1. Test chosen widget works in normal sidebar first.
  2. Activate this plugin
  3. Go to Appearance > widgets and find “shortcode” sidebar
  4. Drag chosen widgets from configured sidebar to shortcodes sidebar. Save.
  5. Go to page where you want configured widget to appear
  6. enter one of: [do_widget widgetname] eg: [do_widget calendar] [do_widget “widget name”]. eg: [do_widget “tag cloud”] [do_widget id=widgetid] in a page or post
  7. If the plugin cannot work out what you want, it will show a debug prompt , click on the debug prompt and look for the id of your widget in the shortcodes sidebar. Try with the id.

More Info | Download

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

Most Useful WordPress Snippets

Code

The story about WordPress is simple – Code is Poetry – and why not it’s all about coding (or poetry, whatever you like to say). WordPress has been formed up with combining hundreds of thousands of short codes, all stringed together. What more? A base code is one which you see already come build up gives your WordPress blog a shape, but what about other “extra” things which you want to add-on yourself. This article speaks about those extra additional codes which you probably one-to-many times search for.

Change Default From Address

The following short code will let you change the default from addresses when WordPress sends out its emails. You need to add the snippet to functions.php file.

Source: WP-Snippets

Get Featured Image Source

Using the following WordPress function will let you get the source of the featured image easily.

Source: WordPress Codex

Exclude a custom post type from search

The short code will let you exclude a custom post type from search results.

Source: WordPress Codex

Add Additional Image Sizes

The short code will let you add an image size to your WordPress site. Make sure you place the code in your functions.php file to use in your theme.

Source: WordPress Codex

Comment Count Shortcode

The shortcode will let you display a specific post’s comment count.

Source: WordPress Codex

Detect iPhone users

The shortcode will let you detect iPhone users.

Functions to Fetch Custom Field Values

Adding the shortcode in your functions.php file will let you fetch custom field values.

Source: WP-Snippets

Limit Search Results to Specific Post Types

On placing the following shortcode in your functions.php file, it lets you exclude your custom post types from search results.

Different admin and theme languages

The shortcode will define one language for admin and the other for theme.

Remove theme editor submenu

Using the snippet to functions.php file will let you remove theme editor submenu.

Source: WP-Snippet

Photo Credit: Flickr/Rosa Menkman

Page 3 of 3

Powered by WordPress & Theme by Anders Norén