How to increase wordpress memory limit

When some plugin or php code needs more memory than allocated in apache server you get a error like

  Fatal error: Allowed memory size of xxxxxx bytes exhausted (tried to allocate xxxxxx bytes) in /home/youruser/public_html/wp-includes/plugin.php on line xxx

To fix this you need increase wordpress memory usage by adding the following line in wp-config.php. This is located in the root of wordpress installation. And you can use FTP client or you can browse the cpanel file manager to edit wp-config and add the code.

  define( 'WP_MEMORY_LIMIT', '256M' );

You can increase it to 64M at first and if you still see the error you can increase it to any number it requires but your server has a memory limit available.

How to create a wordpress plugin, Google Analytics Plugin for Example

To create a wordpress plugin navigate to the installation folder of the wordpress, then wp-content -> plugins folder create a folder with your desired name of the plugin “your-plugin”, then create a php file with same name “your-plugin.php” and add the following code in it.

<?php
/**
 * Plugin Name: Your Plugin Name
 * Plugin URI: https://www.yourwebsite.com/
 * Description: Your Plugin Description
 * Version: 1.0
 * Author: Your Author Name
 * Author URI: https://www.yourwebsite.com
 */

This is the basic code for a wordpress plugin. After that you can add your plugins php functionality like this. I am creating a legacy analytics plugin for the example

<?php
/**
 * Plugin Name: Your Plugin Name
 * Plugin URI: https://www.yourwebsite.com/
 * Description: Your Plugin Description
 * Version: 1.0
 * Author: Your Author Name
 * Author URI: https://www.yourwebsite.com
 */

add_action( 'wp_head', 'add_to_head' );
function add_to_head() {
  echo '';
}

The above code should add the analytics.js to the wordpress head. Then you can add the Analytics Legacy code to the footer like this

<?php
/**
 * Plugin Name: Your Plugin Name
 * Plugin URI: https://www.yourwebsite.com/
 * Description: Your Plugin Description
 * Version: 1.0
 * Author: Your Author Name
 * Author URI: https://www.yourwebsite.com
 */

add_action( 'wp_head', 'add_to_head' );
function add_to_head() {
  echo '';
}
add_action('wp_footer', 'add_to_footer');
function add_to_footer(){
  echo "
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-Your Analytics Number', 'auto');
    ga('send', 'pageview');
  </script>
  ";
}

How to add html code to wordpress Header and Footer

To add html code to the header, use the following code snippet

add_action('wp_head', 'add_html_to head');
function add_html_to head(){
  echo "HTML code goes here";
}

To add html code to the footer, use the following code snippet

add_action('wp_footer', 'add_html_to_footer');
function add_html_to_footer(){
  echo "HTML code goes here";
}

These functions can be called from funstions.php in the theme directory or from a plugin.

How to get current URL path in PHP

echo $_SERVER['REQUEST_URI'];

This will print the current URL path in your website but not the base URL or your domain name for the server. To print the base URL or domain use

echo $_SERVER['SERVER_NAME']

HTML Symbols – HTML entities for writing codes in wordpress post

< = &lt; or &#60; (less than sign)
> = &gt; or &#62; (greater than sign)
/ = &#47; (slash)
\ = &#92; (backslash)
( = &#40; (opening parenthesis)
) = &#41; (closing parenthesis)
] = &#93; (opening bracket)
[ = &#91; (closing bracket)
^ = &#94; (caret - circumflex)
_ = &#95; (underscore)
" = &quot; or &#34; (double quotes)
' = &#39; (single quote)
“ = &ldquo; or &#8220; (left double quotation mark)
” = &rdquo; or &#8220; (right double quotation mark)
‘ = &lsquo; or &#8216; (left single quotation mark)
’ = &rsquo; or &#8217; (right single quotation mark)
& = &amp; or &#38; (ampersand)
! = &#33; (exclamation point)
# = &#35; (number sign)
$ = &#36; (dollar sign)
€ = &#8364; or &euro; (euro sign)
% = &#37; (percent sign)
* = &#42; (asterisk)
+ = &#43; (plus sign)
- = &#45; (minus sign - hyphen)
  = &#32; (space)
, = &#44; (comma)
. = &#46; (period)
: = &#58; (colon)
; = &#59; (semicolon)
= = &#61; (equal sign)
? = &#63; (question mark)
@ = &#64; (at symbol)
` = &#96; (grave accent)
~ = &#126; (equivalency sign - tilde)
© = &#169; or &copy; (copyright sign)
® = &#174; or &reg; (registered trade mark sign)
™ = &#8482; (trade mark sign)
« = &#171; or &laquo; (left double angle quotes)
» = &#187; or &raquo; (right double angle quotes)
• = &#8226; (bullet)

WordPress – How to load a plugin(LiveChat) after the theme

Load LiveChat on a specific or single site on multisite wordpress or any plugin you want

The following tip is a custom solution for wordpress LiveChat. By default live chat loads on every page and every website on a multisite wordpress installation. After wrapping the language check the in the LiveChat initiator file I found that the value was not available to the plugins php file. So I moved the LiveChat initiator code into a function and added the action
add_action( 'after_setup_theme', 'function_name' );

After adding this action I got the desired value for the $_GET[‘lang’] language check.
Following code may help someone that I used on LiveChat Plugin -> livechat.php

add_action( 'after_setup_theme', 'load_live_chat_last' );
function load_live_chat_last (){
 if ($_GET['lang'] == 'en-us') {
  if (is_admin()) {
   require_once(dirname(__FILE__).'/plugin_files/LiveChatAdmin.class.php');
   LiveChatAdmin::get_instance();
  }
  else {
   require_once(dirname(__FILE__).'/plugin_files/LiveChat.class.php');
   LiveChat::get_instance();
  }
 }
}

You can also load LiveChat plugin on a specific or single page by adding url path check as below,

function load_live_chat_last (){
 if ($_GET['lang'] == 'en-us') {
  if($_SERVER['REQUEST_URI'] == "/support/") {
   if (is_admin()) {
    require_once(dirname(__FILE__).'/plugin_files/LiveChatAdmin.class.php');
     LiveChatAdmin::get_instance();
   }
   else {
    require_once(dirname(__FILE__).'/plugin_files/LiveChat.class.php');
    LiveChat::get_instance();
   }
  }
 }
}

Mgento 2 – How to enable merge CSS, JavaScript files

In Magento 2 CSS files can be merged into one single file that helps to optimize the site which increases page loading performance. Same goes for javascript files. You can also minify the merged CSS file and JavaScript file Magento system in the same place. Here is how you can merge CSS or JS files.

Merging CSS files in Magento 2:
Go to Admin panel -> Stores -> Settings -> Configuration -> Advanced -> Developer -> CSS Settings -> Merge CSS Files -> Choose Yes from the dropdown -> Save Config.

Merging CSS files in Magento 2:
Go to Admin panel -> Stores -> Settings -> Configuration -> Advanced -> Developer -> JavaScript Settings -> Merge JavaScript Files -> Choose Yes from the dropdown -> Save Config.