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; }
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.+
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.
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.
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.
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.
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.
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.
123456
password
12345678
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:
I was replaced by 1
L is in lower case
M is replaced by ^^ (Shift + 6 twice)
n for and
W is uppercase as she’s important 🙂
81 is the YY format of my birth year
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.
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:
On your local or web server, browse to the main installation (root) directory for WordPress.
On local if you have enabled hidden files, you will need to enable hidden files.
You will see a file named .maintenance in the root directory.
Simply delete this file to bypass the above mentioned message and you can access your WordPress dashboard and site as you normally do.
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.
Explore IOGOOS uitmate WordPress Development Services
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;
}
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.