WordPress functions.php File

Functions.php is a file found in your Theme’s folder. To understand the file location, look at the following wordpress theme hierarchy.

Adding Code to the Functions File

The functions file is where you put various features and functionality within your wordpress theme. You can achieve this by defining your own functions or by calling built-in WordPress functions. For example, you can control :

  • Use of featured images
  • The image sizes supported by your theme
  • Widgetized areas
  • Decide whether to show post from a particular category in home page or not
  • And  more ….

You can produce the same results by using a WordPress Plugin. In other words the functions file behaves like a WordPress Plugin. But using lots of plugins can slow down your blog’s performance.

When You Shouldn’t Use functions.php

Functions.php is a theme-specific file, which means each theme has its own functions file and any code/function added there strictly related to that particular theme. As soon as you update theme or change your theme, your changes will be wiped out.  See how to use a child theme to add code without worrying about losing your changes.

How do I move WordPress from a sub directory to the root directory

Most website creators using WordPress today to create website. You can easily build and manage your  site with WordPress. When you convert your  your existing business website(.html / .php/ .aspx files)  to wordpress, it’s a good idea to set up a blog and test a new version in a subfolder (example.com/WordPress) so that it does not affect their main domain.  Once completed, you can move the new site over to the root directory for the domain.

This tutorial assumes you have already created, tested your site in a subfolder called “wordpress”. Refer following articles if you need help on how to install wordpress.

  1. How To Install WordPress on the Best WordPress Hosting Providers
  2. How to install a WordPress blog in 1and1?
  3. How To Install WordPress Using Fantastico

Now let us see how to move your site to root.

Step1: Change site URL

  1. Log into your WordPress Admin, go to  Settings -> General.
  2. Change WordPress address (URI) from (example.com/WordPress to example.com)
  3. Change Site Address address (URL) from (example.com/WordPress to example.com)

Step2: Physically move the files from a sub folder to your main folder

Before moving the wordpress files to root, take a backup of your site in root folder. After you have made your backup, it is time to move your WordPress to the primary folder. You can use the cPanel File manager, an FTP program, Shell using SSH, or  HTML editor like DreamWeaver.

Moving Files Using Cpanel

  1. Log into your cPanel  dashboard.
  2. From the main cPanel area, look for the Files category and then click on the File Manager tool.
  3. Once inside the File Manager, you will want to navigate to the folder you have the WordPress site in. (For example, a folder named WordPress.)
  4. You will see a list of all the WordPress files and folders in the right hand panel. Highlight them all and click on the Move File icon from the menu toolbar across the top of the page.
  5. A popup will appear so you can enter the destination folder. Continuing with our WordPress folder example, it should show as public_html/WordPress. Remove the /WordPress from the destination path so that it simply displays as public_html. Click the Move Files button.
  6. This will move the files up to the public_html folder. You should now see the same files as you have in your WordPress folder.
  7. You can now delete the old WordPress folder.

Moving Files Using FTP

Open your FTP program. Select files from “WordPress ” folder.Drag files to root folder.

Your site is ready now.

Display Different Sidebar for Each Post and Page for WordPress

In this article I will show you how to choose display different sidebar for each post and page for WordPress. There’s several different plugins that help you gain this type of flexibility with your site.

Easy Custom Sidebars

custom-sidebar
This plugin allows you to replace any sidebar/widget area in any WordPress theme without any coding.

  1. Go to your wordpress admin >> Plugins >> Add new . In the search box type “Easy Custom Sidebars” and hit enter key to search. Install and activate the Easy Custom Sidebars plugin.
  2. custom-sidebar-02 You will see new menu item “Theme Sidebars” under “Appearence” menu. Click on it.
  3. custom-sidebar-03Create new side bar here.
  4. custom-sidebar-04 Replace your old side bar with new side bar.
  5. custom-sidebar-05 Select posts/pages/categories where you want to display this new side bar. Save your side bar.
  6. custom-sidebar-06 Go to Appearance >> Widgets. Drag a widget to side bar. Edit and save it.

Per Page Sidebars Plugin

Content Aware Sidebars

How to Have Different Sidebar Content On Different Pages of Your WordPress Site

Now when you are writing a post or a page, and you want to display a custom sidebar all you need to do is add the custom field “Sidebar” and include the name of the sidebar file. For example if you insert “wpbpage”, it will display sidebar-wpbpage.php as your sidebar.

Custom Sidebars – Dynamic Widget Area Manager

How to Split a long WordPress Post into Multiple Pages – post pagination

You wrote a very long post and have some issues with load times on your posts, it is better to split that long WordPress post into multiple pages. Reading long posts can be hectic or boring for users. This can increase the bounce rate of your site. So for better presentation and readability, divide along post into several pages. This also will improve the look and feel of your site and increase the number of page views on your site.

Dividing your posts into two or more pages is simple in WordPress.

split-post

  • In the post editor, click on “Text” tab to switch to “Text” editor mode.
  • Add the following tag wherever you want to split your post.

    <!–nextpage–>

    You can add this tag anywhere you want as many times as you want.

  • Save your post.
  • Now you can see post pagination.split-post2

Best WordPress Backup Plugins

It is really important to take regular back up of your blog to guard against losing all your data. Luckily, there are plenty of excellent WordPress plugins available that will back up your posts, pages, and whatever else you have on your site. Let’s take a look at some free WordPress backup plugins! Installing plugins from the WordPress Dashboard is so easy. This guide will show you how to install a WordPress plugin.


BackWPup

wp-backup3The BackWPup Free version can be used to save your complete installation including /wp-content/ and push them to an external Backup Service, like Dropbox, S3, FTP, Microsoft Azure, RackSpaceCloud or to Sugar. With a single backup .zip file you are able to easily restore an installation. This plugin is available via the WordPress Plugins Directory. Type “BackWPup” in Search Plugins box and install it.

BackupBuddy

wp-backup6BackupBuddy Premium is a WordPress backup tool that can handle file and database backups easily. However, BackupBuddy Premium isn’t free. For $75 you’ll get 2 site license, and that’s it. No monthly fees, and this license last a lifetime. Get BackupBuddy

VaultPress

wp-backup7VaultPress is a subscription-based protection, security and backup service for WordPress blogs and sites. VaultPress makes it easy to keep an up-to-date backup of your site with both daily and real time syncing of all your WordPress content. Get VaultPress

BackUpWordPress

wp-backup4 BackUpWordPress will back up your entire site including your database and all your files on a schedule and store in your hosting server. Backups are stored on your server in /wp-content/backups. Option are available to email the backup file to you. You can exclude files and folders from your backups. This plugin works on Linux & Windows Server. This plugin is available via the WordPress Plugins Directory. Type “BackUpWordPress ” in Search Plugins box and install it.

Duplicator

wp-backup2 The Duplicator let you create back up of your site. Using this plugin you can also Duplicate, clone, move and transfer an entire site from one location to another. This plugin works on Linux & Windows Server. This plugin is available via the WordPress Plugins Directory. Type “Duplicator” in Search Plugins box and install it.

WP-DB-Backup

wp-backup5WP-DB-Backup allows you easily to backup your core WordPress database tables. This plugin is available via the WordPress Plugins Directory. Type “WP-DB-Backup” in Search Plugins box and install it.

UpdraftPlus Backup and Restoration

wp-backup1 Backup into the cloud (Amazon S3), Dropbox, Google Drive, Rackspace Cloud, DreamObjects, FTP, Microsoft OneDrive, SFTP, SCP, WebDAV, OpenStack Swift and email.Features icnlude Backup automatically on a repeating schedule, Files and database backups can have separate schedules, Large sites can be split into multiple archives, Select which files to backup (plugins, themes, content, other), Download backup archives direct from your WordPress dashboard, Failed uploads are automatically resumed/retried.

Dropbox Backup & Restore

wp-backup8Create Full Backup (Files + Database) of your blog and save locally at your shared hosting / server of your site or upload to dropbox. Using this, you can easily Backup, Restore, Duplicate, Clone or Migrate of your Website. This plugin is available via the WordPress Plugins Directory. Type “Dropbox Backup & Restore” in Search Plugins box and install it.

WordPress Backup to Dropbox

wp-backup9Keep your blogs back up in Dropbox. Choose a day, time and how often you wish your backup to be performed. Your websites files and a SQL dump of its database will be dropped in your Dropbox! This plugin is available via the WordPress Plugins Directory. Type “WordPress Backup to Dropbox” in Search Plugins box and install it.

10 Essential Things To Do After Installing WordPress

There are few basic settings and configurations to do after installing WordPress to ensure reliability, and top of the line performance.

  1. Change The Title, Tagline and Time zone

    • To change these, go to your Settings in your dashboard and choose General.wp-basic-step2
    • Change both your site title and tagline to something that relates to your site. Now scroll down the page to update your timezone.Change The Title, Tagline, Time zone
    • Scroll down the page click on save changes.
  2. Delete the Default WP Admin Account

    By default WordPress Creates ‘Admin’ as a username for your Blog. Hackers know this and has half the equation to try to get your password. To avoid this, use a different admin username.

    • Login using your admin user account. Once logged in goto Users > Add New wp-basic-user-add1 Fill in all the details for a new user account. Choose the Administrator privileges for this new account .wp-basic-user-add
    • Once that new account is created, log out of your “admin” user account and log back in using your new user account that you just created.
    • Once logged in under the new user account, go to to all User list. Pass the mouse over use “admin” and click on “delete” link.wp-basic-user-delete When you do this WordPress will prompt you to reassign all the posts associated with “admin” to another account. Choose your new account from the drop down list.wp-basic-user-delete2
    • Once you have completed the step of deleting your own “admin” account all the posts previously posted under “admin” will be associated with your new account and you are no longer using the default username.
  3. Delete default Posts and page:

    WordPress install comes with default post and pages. Click on Posts from left menu. Hover over the sample post and select Delete. wp-basic-step3You can delete the sample Page in the same way via Admin -> Pages.

  4. Rename Uncategorized Category

    WordPress install comes with 1 default category named Uncategorized. Unlike the post and the comment this category cannot be deleted. When an editor forgets to select a category, WordPress automatically selects Uncategorized category for that article before it is published. When you have blog posts listed as “Uncategorized,” It makes you seem careless, resulting a symbolic black mark against your blog’s reputation. wp-basic-category3
    To rename the uncategorized category Click on the tab Posts > Categories. Bring your mouse over to Uncategorized and an Edit option will appear. Click Quick edit and change your category name and slug to Other.

  5. Set up WordPress Permalink

    By default, WordPress offers permalinks like this:http://www.wordpressluv.com/?p=123. This type of permalink is not search engine friendly and not very user friendly. More descriptive URL with keywords may boost your rankings.Other than this, permalinks will give a brief idea of what your post or page is about without looking at the content and can affect a reader’s decision whether or not to click links to your site. You can change the structure of your permalinks at any time, however doing this changes the URL of your pages. You should set your permalink when setting up your blog for the first time.

    You can find various permalink settings under WordPress dashboard > Settings > Permalink.wp-basic-permalink1wp-basic-permalink2

  6. Activate Akismet

    Akismet comes with WordPress which eliminates comment and Trackback spams without your interaction.

    • To activate that, you need API key from Akismet It is free you can get it from Akismet.com/get.
    • Click the Plugins link on the left navigation menu of the Dashboard to load the Plugins page.
    • Click the Activate link below the Akismet plugin name and description. A yellow box appears at the top of the page, saying Akismet is almost ready. Go to Akismet Configuration and enter API key to activate it.
  7. Update your Profile

    From your wordpress admin left menu, click on Users and update your profile.wp-basic-user-profile

  8. Install new theme

    Give unique look to your blog. Change default style to any of the best WordPress theme that suits your blog. There are plenty of free and premium themes available.
    Elegant ThemesElegant Themes looks great, is easy to use and as plenty of options to make your site uniquely you. It is also a bit cheaper than most premium themes. Browse more themes from StudioPress.com
    These steps will help you install and select a WordPress theme for your blog..

  9. Delete Unused Themes and Plugins

    After you have installed your WordPress theme and Plugins, Delete all unused Themes and Plugins. It will improve your WordPress Performance, security purpose as well as to reduce the server load. Hacker might discover an exploit those unused themes and plugins.

    Delete Unused Themes

    • From your WordPress dashboard go to Appearance > Themes. Here you can see available themes. This include active theme and other unused themes. You can’t delete an active theme. Pass the mouse over unused themes and click on theme details button. Click on it.
      wp-basic-theme-delete1
    • In the preview screen, click Delete button in the right bottom corner of it. Now your theme is successfully removed.wp-basic-theme-delete2

    Delete Unused Plugins

    • From your WordPress dashboard go to Plugins.
    • wp-basic-plugin-delete1wp-basic-plugin-delete2
  10. Install the Essential Plugins

    It is important to install some plugins for better performance of your website. Thousands of plugins are available in the wordpress plugin directory. You can search and see if there is a plugin that fits your need. Refer the article: How to install a WordPress Plugin. Here is a list of 27+ best plugins for a successful wordPress blog.

  11. Start Scheduling Regular Backups

    It is important to take regular backup of your site. It helps to recover your site in case of server crash or when you need a new host. There are so many free and premium backup plugins available that creates backup of your website and keep your site safe and secure.backup buddy

  12. Add Contact me page

    Use plugin Contact Form 7 to add contact page to your site.

How To copy a single post From One WordPress Website to Another

There may be a number of reasons for copying your post or page. For example, you own two WordPress blogs, and you have written some pre-configured post/page with some basic look and want to use same format in another site without worrying about how to format everything. Let us see how to copy specific posts and pages from one of your WordPress site  to another WordPress site.

You can do this in 4 steps.

  1. Create a new category with unique name
  2. Find the post you want to move and put that post in new category.
  3. Export the post in new category.
  4. Import it to new site.

#1: Create a new category

  • From your blog’s dashboard go to Posts » Categories

    add category
    add category
  • Just fill the fields and click Add category button. For eg. here I am going to create a new category called ‘Export’.
    add-category
    create category

    Note: You can leave the slug, Parent and description blank.

#2: Edit the post, assign new category

  • From your blog’s dashboard go to Posts –> All Posts.
  • Find the post you want to copy.
    post-quick-edit
    edit post

    Hover your cursor over the title of that post. Click the small Quick Edit link beneath the post’s name.The post title will expand to become an editing pane:

  • post-quick-edit
    add category here

    Here select the newly created category. Click Update.

#3: Export the post

  • export
    Tools- export

    From your blog’s dashboard, find the “Tools” menu on the left hand side, near the bottom of the dashboard.Choose the “Export”from the list of options.

  • Here you will have and option to decide what you want to export. In step 1 we created a new category and in step 2 we selected the post you want to move and put it in new category. Now we are going to export the post in that category. Click on post and you will see more options.
    export
    select export category

    Select newly crated category here. Click “Download Export File” to create an “XML” file of your entire blog on your computer.

  • export3
    Save XML file

    Save the file in an easy to access folder, or on your desktop. You will need this file in order to import it later.

#4: Import Post to new site

  • tools-import
    tools >> import

    Log into your wordpress blog and find the “Tools” menu on the left hand side, near the bottom of the dashboard.Choose the “Import”from the list of options.

  • Choose the WordPress option.
    choose wordpress
    choose wordpress

    If you haven’t yet installed the importer plugin on This will bring up a popup to install the plugin. Click “Install Now.”

    install plugin
    install plugin
  • After installing and activating the plugin, browse for your XML file on your computer.
    upload file
    upload file

    Click “Upload” to upload the XML file to the new blog.

  • In the next screen, it would ask if you need to create a new user or if you want to assign the posts to existing user.
    assign author
    assign author

    Just select to assign the posts to the existing author user on the destination blog so that she would be author of the WordPress posts imported. Select “Download & import file attachments” to move your media along with the post.

  • Now you are done exporting a single post on the WordPress site. You can open the post in edit mode to make changes.
    edit post
    edit post

    Note: If you do not want to keep the newly created category, you can remove it from post categories or delete it from categories list(go to Post>>categories and delete it).

 

What is the difference between the hierarchical and Non-Hierarchical Taxonomies?

When I was using a plugin to create and , I came across following situation.

After creating custom taxonomy, I was hoping for was a simple option where I could uses the check box UI for selecting categories on each post.

checkbox UI
check box UI

Instead of that I got comma-separated text input.

text box
text box

I did some research and found out that, that plugin use a setting “Hierarchical ==>> false” when registering custom taxonomy.
‘hierarchical’=>false you get the metabox   format WordPress uses for Post Tags:

hierarchical=>false
hierarchical=>false

‘hierarchical’=>true you get the meta box format that WordPress uses for Categories:

hierarchical=>true

A Guide to WordPress Custom Fields

When you write a post/content on your blog, in you post writing page you will see the fields for entering  title and body content. If you take a look at the WordPress post writing page you’ll notice a section below the post content text area is titled Custom Fields.

custom fields
custom fields

What if I don’t see Custom Fields section in post writing page?

There’s a chance you won’t see this feature. If not, look to the top right of your window and click Screen Options.

Screen Options
Screen Options

From there make sure the Custom Fields option is selected.

select custom fields
select custom fields

Once selected you should see it at the bottom of your screen like I have above.

Custom fields

Custom fields allow you to add little bits of data to posts. The custom fields section contains two input fields labelled Name and Value. The key identifies the specific field and the value is the information that will be displayed.

For examples if you are writing a post about a tourist place you can add Custom field like “Today’s Weather”, and then add the value “Sunny”.

custom fields
custom fields

This extra information is known as meta-data. Now this information related to your post can be displayed anywhere within your WordPress theme.

Make your Theme ready with Custom Fields

Custom fields don’t display by default unless your theme has been customized to do so. In order to get these values to display we need to add a small amount of PHP to our WordPress loop function inside our theme’s code. Let’s do that now.

To start you’ll need a code editor and access to your theme directory which is located at wp-content/themes/themename.

Open single.php file inside a code editor. Find where your main WordPress Loop starts.

WordPress Loop  starts
WordPress Loop starts

Add this code inside the WordPress loop to display all custom fields associated with that post.

Call the_meta()
the_meta()

the_meta” function will display all fields associated with that post.If you have 10 different fields that you want to display at 10 different locations, then we will have to use “get_post_meta” function.

 use get_post_meta hook
use get_post_meta function