Change WordPress Excerpt Length

You can add the following code in your theme’s functions.php file to change the WordPress excerpt length. Change the number (100) to the desired length.

add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_length($length) { return 100; }
contact us

IOGOOS WordPress development services

How-To: Copy current directory path in Terminal

While working on multiple projects I always need to copy the current path of a directory in Terminal. I used to use the command pwd in the terminal that prints the current directory path in the terminal and then I have to select the path with the mouse to copy and paste the same where I needed.

I hate to use the mouse as it wastes a lot of time and to save time and copy the current path without selecting it with the mouse, I found this command and use it all the time.

pwd | pbcopy

This command will copy the current directory path to the clipboard and we can then press CMD+V (CTRL+V for Windows) to paste the path wherever needed.

I hope this will help someone save time and be more productive.+

img

Our Services

How-to: Get Current Url in PHP with or without Query String

In each PHP website, we need to find out the current URL of the page, and here’s the PHP code to find out the current URL of the page a user is browsing with or without the query string.

function currentUrl( $trim_query_string = false ) {
    $pageURL = (isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on') ? "//" : "//";
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    if( ! $trim_query_string ) {
        return $pageURL;
    } else {
        $url = explode( '?', $pageURL );
        return $url[0];
    }
}

I like to keep such functions in a helpers class so I can use them anywhere in the app. To use it in a PHP class you can use the following code:

public function currentUrl( $trim_query_string = false ) {
    $pageURL = (isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on') ? "//" : "//";
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    if( ! $trim_query_string ) {
        return $pageURL;
    } else {
        $url = explode( '?', $pageURL );
        return $url[0];
    }
}
Contact Us

Our Services

How-To: Create Easy Element Toggles with Data Attributes and jQuery.

While working on my latest WordPress plugin, I found myself using jQuery toggleClass on multiple elements and writing JS code for each was not at all a better solution. To fix this issue and keep the code clean and short I used the following code.

$(document).on('click', '[data-toggle="class"]', function () {
    var $target = $($(this).data('target'));
    var classes = $(this).data('classes');
    $target.toggleClass(classes);
    return false;
});

Make sure you have jQuery script on your page and add this code to your Javascript file and then you can use it in your HTML code as below:

<a href="#" data-toggle="class" data-target="#element" data-classes="is-active">Click here</a> to toggle.
<div id="element">...content goes here...</div>

The anchor tag with data-toggle will look for an element with ID or element and toggle is-active class for that element. You can apply this logic to any UI element such as Modal with an overlay background and use the data-toggle attributes on the modal background as well to hide the modal.

Feel free to implement and extend this code on your projects.

contact us

Our services

Sending email takes a long time on NGINX? Here’s how to fix

I’ve recently switched our servers from Apache to NGINX. While testing our WP Form Builder Add-on, I found that my web server took pretty long time for the mail function to process, however, on the local server, everything works pretty smooth.

While digging Google, I found the solution which fixed this issue. If you are facing the same problem, follow the steps below to resolve it.

Log in to your server via SSH as root user and run the following command:

nano /etc/hosts

You will find an entry that looks like this

127.0.0.1 localhost

All you need to do is add localhost. local domain after this so it should look like this:

127.0.0.1 localhost localhost.localdomain

Press CTRL+X and then Y to save the file. Now, your server mail should process in nanoseconds.

Sometimes, a small fix with a few characters here and there can waste hours. I thought I’d share this here so that it will save some of your time.

Contact Us

Our Services

Expand Images to parent DIV with jQuery and CSS

Working on a WordPress project where the client demands all images within a post should extend and touch window borders, actually full-size images. Applying DIV with jQuery and CSS works. The wrapper has a margin of 20px on both sides and it is not possible to remove the margin otherwise, all other elements will require a 20px margin.

I got this working with the following JS code:

$('.content img').each(function() {
    $(this).css({
        'position': 'relative',
        'min-width': $(window).width(),
        'margin-left': '-20px',
    });
});

In case you have better code for this and in CSS, please share.

DIV with jQuery and CSS
Contact Us

Our Services

How-To: Create a Cron Job to start MySQL if it Stops

Sometimes server acts weird and stops some services due to any issue. I faced this issue with my iogoos.com WordPress demo sites server, where MySQL service stops after running the clean script to remove demo sites after three days. So I created a Cron Job on my GCP VM Ubuntu Droplet to check if and start MySQL service if it’s not running. I scheduled this to run the check every minute. Here’s the code and steps to set up this cron job.

NOTE: You must have ssh access to your server. GCP provides ssh access as soon as you create a droplet.

Creating Shell Script

Step 1: Open Terminal and login to your server as root via ssh.

Step 2: Create shell script file.

cd ~
nano mysqlfix.sh

This will let you create a shell script in the root directory for the root user. You can use any name as per your preferences for the .sh file.

Step 3: Write the script to check and restart MySQL and send an email alert.

#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
then
    echo "MySQL restarted" | mail -s "Email Subject" email@domain.com
    sudo service mysql start
fi

Make sure you change the Email Subject and email address.

Step 4: Once you are done with the script press CTRL + x and you will be asked to save the changes. Type Y and hit enter. You will be returned to the terminal and mysqlfix.sh file will be created in the root directory.

Step 5: Give this file executable permissions

chmod +x mysqlfix.sh

Testing the Script

Now our script is ready, let’s test if this runs fine.

Enter following commands in the terminal:

/usr/sbin/service mysql status

The terminal will print something like this:
mysql start/running, process 2409

/usr/sbin/service mysql stop

This will stop MySQL service, to verify run the status command again and it will print something like this:
mysql stop/waiting

~/mysqlfix.sh

This will run the script we created to check and restart the service. You should get an email with the subject and message to the email address you specified in the script.

Run the status command again and it should print
mysql start/running, process ####

If everything goes well in this step, let’s create the cron job to run our script every minute.

Create Cron Job

Step 1: Installing the cron job

Make sure you are logged into your server via ssh as root, then type the following command in terminal:

crontab -e

Once you see the crontab screen type the following line at the end of this file:

*/1 * * * * /root/mysqlfix.sh

Press CTRL + x and you will be asked to save the changes, press Y and hit enter. You will see the following line in terminal:
crontab: installing new crontab

Now our cron job is installed.

To test if it runs fine, Type following command:

/usr/sbin/service mysql stop

This will stop MySQL service on your server. Now you should wait for one minute and get an email with the subject and message we specified in the mysqlfix.sh file.

Hope you find this helpful.

WordPress Developer
contact us

Our Services

How to create an easy to remember but the super-strong password

Today we spend most of our time online, either on our personal computers, in-office work-station and most of the time on mobile phones. Today there’s a web or mobile app for almost everything and we use almost all of them in our daily routine.

Most of the applications store our information to personalize the content as per our profile and interests. To keep our data secure and hidden from others, they provide us with a form to create a username and password.

Do you use a super-strong password or just an easy one that you can remember and someone else can guess to hack into your account?

I couldn’t believe that most internet users use one of the passwords below to keep their accounts secure.

  1. 123456
  2. password
  3. 12345678
  4. abc123789

I hope you are not one of these people and actually have a really strong password. However, in this article, I am going to explain an easy way to create a super-strong password that you can easily remember.

A super-strong password must be alphanumeric and must contain capital letters and special characters. Now how can we create a password that contains everything so we don’t forget and get locked down from the applications we use.

What do you think of this password?

1l^^|<nW8106

Do you think it’s a super-strong password? Can you remember this every time you are asked to punch this password?

If you think you can’t, then let me explain how this password is created and make your life a lot easier and more secure.

I Love My Kids and Wife 1981 2006

Here’s a simple line that I can remember always. Of course, I love my kids and wife, and I was born in 1981 and got married in 2006 which is why I have a wife and kids 😉

Now let’s create a password out of it:

  1. I was replaced by 1
  2. L is in lower case
  3. M is replaced by ^^ (Shift + 6 twice)
  4. n for and
  5. W is uppercase as she’s important 🙂
  6. 81 is the YY format of my birth year
  7. 60 is the YY format of my anniversary

Combining all these characters makes this jumbled text a super-strong password.

NOTE: This is just an example and I request you, not to use this line for your password as a lot of people will read this post.

Be a little creative and think of phrases that you can not forget and try to replace the characters with symbols. Once done, do write your new password at least 10 times somewhere, and then destroy that file or paper to make sure you do remember what you have set and no one has access to it.

Now you have a super-strong password, so go on, enjoy the current technology and be SAFE. Do share this trick with your friends and family and help them avoid common mistakes and get webbed.

Our Services

WordPress crashed while updating plugins?

Recently I was updating my plugins on my local server and somehow the page got refreshed and my WordPress installation got stuck at the following message:

“Briefly unavailable for scheduled maintenance. Check back in a minute.”

You can easily bypass this message via the following steps:

  1. On your local or web server, browse to the main installation (root) directory for WordPress.
  2. On local if you have enabled hidden files, you will need to enable hidden files.
  3. You will see a file named .maintenance in the root directory.
  4. Simply delete this file to bypass the above mentioned message and you can access your WordPress dashboard and site as you normally do.
  5. You can choose to perform the upgrades again and make sure the page should not get refreshed. If it does again follow the step again.
contact us

Explore IOGOOS uitmate WordPress Development Services

PHP – Flatten or Merge a Multidimensional Array

Here’s a code snippet to flatten or merge a multidimensional array. This is useful when we need to find if a value exists in any of the nodes in a multidimensional array.

I use this function in my Paid Content Packages WordPress Plugin to find out if any of the packages have any page or post assigned.

PHP Function:

function flattenArray($arrayToFlatten) {

	$flatArray = array();

	foreach($arrayToFlatten as $element) {
		if (is_array($element)) {
			$flatArray = array_merge($flatArray, flattenArray($element));
		} else {
			$flatArray[] = $element;
		}
	}

	return $flatArray;
}

Example:

$array = array(
	'parent-one' => 'parent-one',
	'parent-two' => 'parent-two',
	'parent-three' => array(
		'child-one' => 'child-one',
		'child-two' => 'child-two',
		'child-three' => array(
			'kid-one' => 'kid-one',
			'kid-two' => 'kid-two',
		),
	),
);
print_r(flattenArray($array));

This code will print the following output.

Array
(
    [0] => parent-one
    [1] => parent-two
    [2] => child-one
    [3] => child-two
    [4] => kid-one
    [5] => kid-two
)
contact us

There are shorter versions of this function available, however, I like to use code that is clear and easy to read. Hope this helps you if you are finding a solution to this.

Our Services

Enquiry Now

When We Work Together

We can create something incredible

arrow
HQ INDIA
HQ INDIA
C-31, Milap Nagar,
Uttam Nagar, New Delhi,
Delhi 110059
USA
USA
6715 Backlick Rd Suite 202
Springfield,
VA 22150, USA
AUSTRALIA
AUSTRALIA
2/51, Lane Cres,
Reservoir, VIC
3037, Australia
CANADA
CANADA
61 Payzant Bog Road, Falmouth, NS, B0P 1P0, CANADA
UK
UK
3rd Floor, 131 City Road, London, EC1V 2NX, United Kingdom
UAE
UAE
Boutik Mall, Al Reem Island - Abu Dhabi, UAE
X

Let Us Call You Back

  • India+91
  • United States+1
  • United Arab Emirates+971

Your phone number is kept confidential
and not shared with others.