Fix: WordPress Memory Exhausted Error – Increase WordPress Memory Limit

Sometime you might have to face an error while activating a new plugin or doing some other stuff. This error might look like:

 The most possible reason for this error is that you have exceeded your default Memory Limit.

Since WordPress 2.5 there is a wp-config.php option WP_MEMORY_LIMIT which allows you to change the maximum amount of memory allocated to your website. If you change this option for your website it will only affect your WordPress website and not other PHP websites on the server.

WordPress allocates 40MB for single websites and 64MB  for multisite installation. But the php.ini allocated memory supersede the wp-config.php value. For example, if php.ini is configured to 64MB and your WordPress allocated 40MB memory, then the website will 64MB not 40 MB memory.

There are number of ways to fix this error. Some are listed below:

From wp-config.php

To change the WordPress memory limit you just add the following into the wp-config.php.

WordPress memory can be different to the server – you need to set this regardless of server memory settings

From php.ini

If you have access to your php.ini file, then you can change the line in php.ini. Search for the property memory_limit and change the value to something greater like 64M

 From .htaccess

If you don’t have the access to php.ini file you can change the memory limit from the .htaccess file. Go to the root folder of your website and create a new .htaccess file if it doesn’t already exist and add the following line to your htaccess file.

 If none of the above methods work, please contact your hosting service provider.

Everything about WordPress Child Themes

As more and more WordPress users now customize their themes and only few users like the themes in default mode we will learn in this article how to create a Child Theme from a WordPress Theme.

Why use a Child Theme?

You will save yourself from a lot of headache by creating a child theme. Child theme allows you to make changes without affecting the original theme, which will in turn make it easier to update your parent theme to latest versions without loosing all the changes you made. In the child theme you create a completely separate set of files that you can use to customize the theme without affecting the original theme. This way you will make sure that your original theme is intact as you are not making any changes to it.

Getting Started

  1. Create a new folder/directory in your themes folder. This new folder will contain you child theme. For our reference we will create a child theme of WordPress Twenty Fourteen Theme.
  2. In the child theme folder create a stylesheet file named style.css. This is the only required file for a Child Theme. Open the newly creates file and put the following code at the top.

    You can make changes to the above code according to your suitability. Only Theme Name and Template are required, all the rest are optional. The Template value is the name of the directory of the parent theme.

  3. Go to your website’s dashboard, and go to Administrator Panel -> Appearance -> Themes. Here you will now see your newly create theme among the list of other themes. Activate the Child Theme.

Editing the functions.php File

The functions.php of a child theme does not override its counterpart in the parent them unlike style.css. It is loaded in addition to the parents function.php not in place of it. Your child theme’s functions.php file should start with a php opening tag and end with a php closing tag. In between, you can add your desired php code.

 For example, you want to add a new function to you theme, the fastest way is that you open your theme’s function.php and add the new function. But now if you update your theme the new function added by you will be removed. The better way is that you add the new function toy your child theme’s function.php. 

Editing Other Templates

If you want to make structural changes to your theme by changing PHP template files, this can be done by replacing the file entirely with a new one  in your child theme. Your child theme can override any file in the parent theme: simply include a file of the same name in the child theme directory, and it will override the equivalent file in the parent theme directory when your site loads. For instance, if you want to change the PHP code for the site header, you can include a header.php in your child theme’s directory, and that file will be used instead of the parent theme’s header.php.

Decoding WordPress wp-config.php

wp-config,php is one of the most important file of a WordPress installation. This file is located in the root of your WordPress file directory and contains your website’s base configuration details, such as database connection information. In this article we will try to understand all the settings that are done in wp-config.php and their usage.

Database Settings

  • DB_NAME: This will be the name of your WordPress database.
  • DB_USER: This will the username to access your database.
  • DB_PASSWORD: This will the password to access your database.
  • DB_HOST: This will the hostname of your database server. Most of the times its localhost. But if you are not sure you can ask you hosting company and they will provide you the database server information of your server. Below is a table of possible database hosts.
  • DB_CHARSET: This will define the character set used by your database.The default is utf8 which supports all languages, so it should not be changed unless absolutely necessary.
  • DB_COLLATE: Used to define the sort order of the database character set. if you are changing this value, make sure is is set to a UTF-8 character set, such as utf8_general_ci or utf8_spanish_ci
Hosting Company Possible DB_HOST values
1and1 db12345678
AN Hosting localhost
Aruba.it localhost or real IP provided with activation mail.
A Small Orange localhost
BlueHost localhost
DreamHost mysql.example.com
GoDaddy – Shared and 4GH Hosting In the Databases menu go to MySQL. To the right of the database name click on Actions and Details. The hostname is at the bottom of the window.
GoDaddy – cPanel Hosting localhost
GoDaddy – Plesk Hosting Use the IP address shown in the Databases Section in Plesk. Do not include :3306
HostGator localhost
HostICan localhost
ICDSoft localhost:/tmp/mysql5.sock
Infomaniak Network mysql.yourdomain
InMotion Hosting localhost
iPage username.ipagemysql.com
IPower username.ipowermysql.com
LaughingSquid localhost
MediaTemple Grid internal-db.s00000.gridserver.com – (Replace “00000” with the actual site number)
MediaTemple DV localhost
MegnaHost localhost
NearlyFreeSpeech.Net username.db
NetworkSolutions mysqlv5
one.com example.com.mysql
pair Networks dbnnnx.pair.com
QTH.com localhost
Rackspace Cloud localhost for unmanaged servers, variable for Cloud Sites like mysqlXY-AB.wcN.dfQ.stabletransit.com where X,Y,A,B,N,Q are variables
SysFix.eu Power Hosting datapower.sysfix.eu
Yahoo mysql
Hosts with cPanel localhost
Hosts with Plesk localhost
Hosts with DirectAdmin localhost
Tophost.it sql.your-domain-name.it

Table Prefix

The $table_prefix is the value placed in the front of your database tables. If you haven’t changed this while installing the WordPress, then most probably you are using the default wp_ as table prefix.  From security perspective, this is very unsafe and this should be changes as soon as possible. If you are an advance user you can change it manually by replacing wp_ by something random like aedc_ and then updating the database tables. But if you are not and advance user you can do it by using some security plugin such as iThemes Secutiry.

You can have multiple installations in one database if you give each a unique prefix.

 A second blog installation using the same database can be achieved simply by using a different prefix than your other installation.

Security Settings

A secret key is a password with elements that make it harder to generate options to break through you security barriers. All the keys are randomly auto-generated and should not be disclosed to anyone.

You can assign any random string to these keys or you can use the online generator to generate security keys.

These keys will be used to sign the cookies for your website.

  • AUTH_KEY: This key is used to sign auth cookies for the non-SSL. These can also be used to make changes on the blog.
  • SECURE_AUTH_KEY: It is used to sign an auth cookie for SSL admin and these cookie can be used to make changes on blog. (With the new version there will be two type of auth cookie one for SSL and other for non-SSL)
  • LOGGED_IN_KEY: It will be used to generate a cookie for a logged in user and this cookie can’t be used to make changes on the blog.
  • NONCE_KEY: It is used to sign the nonce key which protects the nonces from being generated, protecting you from certain forms of attacks where a hacker attempts to guess the nonce.

Salt is an addition to the secret keys. They work in combination with keys.

There are 4 salts named as AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT, and NONCE_SALT.

Defining them is not compulsory, but it is a good practice to have them in your wp-config.php file. If you don’t define those than WordPress will generate it automatically. These can also be a random complex string and you can define them either by yourself or through the online random key generator.

Language and Language Directory

  • WPLANG: It defines the name of the language translation (.mo) file.If your blog is in English, leave it blank. But if your blog is in a language other than English, you can look up your language code here: http://codex.wordpress.org/WordPress_in_Your_Language. For example, for Spanish the code will be 
  • WP_LANG_DIR: This defines what directory the WPLANG .mo file resides. If WP_LANG_DIR is not defined WordPress looks first to wp-content/languages and then wp-includes/languages for the .mo defined by WPLANG file.

Debug Settings

  • WP_DEBUG: This option controls the reporting if errors and warnings. This is set to false by default. But if you wish to debug code you must set it to true.
  • CONCATENATE_SCRIPTS: This option will concatenate all the JavaScript into one for a faster Administrator area. This is set to true by default, but if the JavaScript is not working properly in your Administrator area you can set it to false.

WordPress Permalinks

WordPress Permalinks are the permanent URL’s to the individual posts, pages, as well as categories and other lists of the WordPress blog postings. It is called permalink because the URL to each post should be permanent, and never change — hence permalink.

Different web server use different modules for creating permalinks. Permalinks are available under:

  • Apache web server with the mod_rewrite module
  • Microsoft IIS 7+ web server with the URL Rewrite 1.1+ module and PHP 5 running as FastCGI
  • Microsoft IIS 6+ using ASAPI_Rewrite
  • Lighttpd using a 404 handler or mod_rewrite

Choosing your permalink structure

In the Settings → Permalinks panel (Options → Permalinks before WordPress 2.5), you can choose one of the “common” structures or enter your own in the “Custom structure” field using the structure tags.

Please note: You never, ever put your site url in the permalinks slot. You must use one of the structure tags, or a combination of tags only. To activate PATHINFO permalinks, start your permalink structure with index.php/.

permalink-settings

Structure Tags :

You can use these tags to customize your “Pretty” or “Almost Pretty” permalinks.  Make sure to end your structure with either %post_id% or %postname% (e.g. /%year%/%monthnum%/%day%/%postname%/) so that each permalink points to an individual post.

Following is the list of the structure tags:

  •  %year%  : The year of the post, four digits, for example 2013
  •  %monthnum%  :  Month of the year, for example 03
  • %day% : Day of the month, for example 15
  • %hour% : Hour of the day, for example 16
  • %minute% : Minute of the hour, for example 43
  • %second% : Second of the minute, for example 33
  • %post_id% : The unique ID # of the post, for example 423
  • %postname% : A sanitized version of the title of the post (post slug field on Edit Post/Page panel). So “This Is A Great Post!” becomes this-is-a-great-post in the URI.
  • %category% : A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI.
  • %author% : A sanitized version of the author name. 

Category base and Tag base

The Category base and Tag base are prefixes used in URLs for category and tag archives, which look like this:

  • example.net/wp/category_base/category_name
  • example.net/wp/tag_base/tag_name 

The default values for these are category and tag. You can change them, but you can’t remove them from the URLs altogether. Custom permalinks work on most systems without any problems, but there are still some conditions where problems occur. 

How-To: Write a WordPress Plugin

WordPress Plugins help us to easily modify , customize and enhance the WordPress Blog. We can use the WordPress Plugins to add functionality to WordPress instead of the modifying the core programming of the WordPress.

If you need a specific functionality for your blog you must first search WordPress Repository for existing plugins to see if someone has already developed a plugin that suits your requirements. If not then you should proceed developing your own plugin which is explained below:

I assume that you are already familiar with the basic functionality of WordPress, and PHP programming.

Creating a Plugin

This section will take you through the steps of creating a well-structured WordPress Plugin.

Names, Files, and Locations

Plugin Name

You should choose a name for your plugin which describes what the plugin is going to do. For example a Stock Exchange related plugin should use wordpress Stocks in its name. You should also check the WordPress repository to check if the proposed name is available or already taken .

Plugin Files

Create a plugin file with the name based on the name of the plugin. It is not cumplosary but you should follow the rules. You can place this file directly under the /wp-content/plugins/ directory or in the directory of you plugin (e.g: /wp-content/plugins/your-plugin/

Readme File

If you want to host your Plugin on http://wordpress.org/extend/plugins/, you also need to create a readme.txt file in a standard format, and include it with your Plugin. See http://wordpress.org/extend/plugins/about/readme.txt for a description of the format.

Note that the WordPress plugin repository takes the “Requires” and “Tested up to” versions from the readme.txt in the stable tag.

 Creating Plugin Files

Now it’s time to put some information into your main Plugin PHP file.

Standard Plugin Information

Your Plugin’s main PHP must start with the following code. 

 These lines will serve as the definition of your plugin. You can write your plugin code after these lines. The whole plugin logic will follow these lines .

How-To: Create a WordPress Theme in 5 minutes

It is fairly easy to create a WordPress Theme. A few things before you need a template are:

  1. Create a layout of your blog by figuring out what is to be placed where.
  2. Create a HTML layout based on the above layout.

A sample layout which we are using in this tutorial can be seen in the image here.theme-layout

Right Then !!! We are ready to proceed

The files necessary for a theme to function properly in WordPress are:

  1. header.php -> Header
  2. index.php -> Content glued with header, sidebar and footer.
  3. sidebar.php -> Sidebar
  4. footer.php -> Footer
  5. style.css -> CSS

Now we will write some sample code for all the default files

The header.php

   

Basically, this is simple HTML code with a single line containing a php code and a standard WordPress function. In this file you can specify your meta tags such as the title of your website, meta description and the keywords for your page.

Right after the title the line we add

. This tells WordPress to load the style.css file for the theme. It will handle the styling of your website. The part of the line is a WordPress function that loads the stylesheet file.

Next, we have added the beginning of a “div” with class wrapper which will be the main container of the website. We have set class for it so we can modify it via the style.css file.

After that we have added a simple label HEADER wrapped in a “div” with class “header” which will be later specified in the stylesheet file.

The index.php file

Main Area

 

Posted on

 


 

The code in this file begins with  which will include the header.php file and the code in it in the main page. It uses an WordPress function to do this. Then we have placed a Main Area text to indicate which section of your theme is displayed in this area.

The code next to the  function checks whether your WordPress installation has posts to publish or not. If it has posts, they are displayed.

After this we will include the sidebar.php file with this line –. In this file you can display your post categories, archives etc.

After this line, we insert an empty “div” that will separate the Main Area and the Sidebar from the footer.

Finally, we add one last line – which will include the footer.php file in your page.

The sidebar.php file

In the sidebar.php we will add the following code:

In the sidebar.php file we use internal WordPress functions to display the Categories and Archives of posts. The WordPress function returns them as list items, therefore we have wrapped the actual functions in unsorted lists (the tags).

The footer.php file

We have added these lines to the footer.php file:

With this code we add a simple FOOTER label. You can also add additional links in the footer.

The style.css file

The style.css will handle the styling of the theme. Add the following lines to the style.css file to create some styling for the theme:

This simple css file sets the basic looks of your theme. The theme will look something like the image here:

theme-sample1
So after doing all this we have basic theme functional.

How-to: Create Multiple Dynamic Sidebars for WordPress Widgets

In this post we will learn how to create multiple dynamic sidebars for WordPress widgets which will in turn help you customize your WordPress Theme even more.

Follow the under mentioned simple steps:

Edit functions.php for Multiple Dynamic Sidebars

The functions.php in a theme usually comes with a code to add at least one sidebar widget. We will now edit this functions.php to add multiple sidebar to the WordPress theme. All we need is to use the following function.

The $args parameter supplied to the register_sidebar can have following values:

The parameters to the function are described below:

args: (string/array) (optional) Builds Sidebar based off of ‘name’ and ‘id’ values.

Default: None

  • name – Sidebar name (default is localized ‘Sidebar’ and numeric ID).
  • id – Sidebar id – Must be all in lowercase, with no spaces (default is a numeric auto-incremented ID).
  • description – Text description of what/where the sidebar is. Shown on widget management screen.
  • class – CSS class name to assign to the widget HTML (default: empty).
  • before_widget – HTML to place before every widget(default: ‘<li id=”%1$s” class=”widget %2$s”>’) Note: uses sprintf for variable substitution
  • after_widget – HTML to place after every widget (default: “</li>n”).
  • before_title – HTML to place before every title (default: <h2 class=”widgettitle”>).
  • after_title – HTML to place after every title (default: “</h2>n”).

In the example below you can see that two sidebars are registered with the name sidebar1 and sidebar2. The code now looks like this –

After writing this code the the functions.php if you now visit your widgets area you can see the two sidebars appearing there. Now you can drag and drop widgets of your choice to both the sidebars and customize the options. Remember to Save Changes or else all customization is lost.

Add Dynamic Sidebars to WordPress Template

Now we need to place the code in the WordPress Theme template wherever we want the sidebars to appear in our template.

Sidebar1 code goes like this

Sidebar2 code goes like this

Save the template and watch your widgets go live. You can add any number of dynamic sidebars in any combination to your theme.