WordPress Cron, how to implement wordpress crons

What is a cron job and how to implement it in WordPress?

What is a cron?

A cron was first used in UNIX operating system to execute specific commands automatically on a specific time instead of executing them manually. In simple words “a cron is a time-based scheduler“.

What is a WordPress Cron?

A  WordPress cron refers to “pseudo-cron system”, WordPres cron job is a scheduled job that runs on a given time automatically.

Limitation of WordPress Cron:

WordPress cron will only run if any user visits your WordPress website’s page/post. Then WordPress will check for any available crons and execute them.

There are two types of crons in WordPress:

  1. Which runs on a specific time automatically and dies.
  2. Second, which run at a specific time automatically again and again.

A cron job may be of any type. It may be an automatic backup taking job, it may be an automatic emails sending job and list goes on depending on what you want to get done.

You can set a cron job by accessing your site’s Cpanel and it is possible some hosts might not be permitting you to set up a cron job for security reasons.

Instead of accessing crons from your site’s cPanel, you can also access crons from WordPress.

A cron job which sets up using cPanel, doesn’t need to check that visitor visits your site, cron will execute automatically at its specific time.

But, WordPress cron will only run if anyone visits your WordPress website, then WordPress checks whether the time is passed or not.

A thing to keep in mind:

“Never ever perform heavy processes in your cron job unless you have a super host like a dedicated host system with maximum performance. Otherwise, it will slow down the server.”

Usage of cron job

What do we need to know about setting up a cron job in WordPress?

WordPress cron job can be setup without using any coding simply by following the suggested steps:

1- Go to Tools and visit Cron Events page

2- Then scroll down to ‘Add Cron Event’ tab.

There you will be required  to provide a hook name for your cron event. Please keep in mind hook names must not have spaces or special characters.

What  does WordPress cron job do in WordPress?

WordPress core and a number of plugins use WordPress Cron to execute the following tasks at regular, repeating intervals:

  1. Checking the updates for plugins and themes.
  2. Checking the WordPress version to ensure it’s up to date.
  3. Backing up the website and database.
  4. Optimizing the database to improve performance.

Below are some examples of WordPress cron jobs which fire only once at a fixed time:

  1. Sending emails at a specific time.
  2. Publishing a blog post at a specific time.

Take a look on the following code snippet:

register_activation_hook( __FILE__, 'activate_cron_job' );
/**
* On activation, set a time, frequency and name of an action hook to be scheduled.
*/
function activate_cron_job() {
wp_schedule_event( time(), 'hourly', 'hourly_cron_job_hook' );
}

add_action( 'hourly_cron_job_hook', 'do_this_hourly' );
/**
* On the scheduled action hook, run the function.
*/
function do_this_hourly() {
// do something every hour
}

register_activation_hook triggered when plugin is activated, and will activate our cron job. First argument of wp_schedule_event is taking the current time and the second argument is about the time interval, like daily, twice daily or hourly. And the third argument is the function hook which will actullay call the original function “do_this_hourly”.

Let us know in comments below, if it helps you with your WordPress website.

create a froum on WordPress without PHP scripts

Create a forum on WordPress without PHP Scripts

WordPress is known as the easiest and simplest solution to make your own website with a low cost or even free if you use their service. However, it’s also very powerful with plugins and themes being developed daily, this means that you can do anything with it such as creating a forum on WordPress. bbPress sounds like a good idea isn’t it? But no, we’re not going to name it in our list today because we found its alternatives.

What are the benefits of having a  WordPress Forum Without PHP

Of course! Building a forum website with WordPress can be really difficult especially when it comes to people spamming with their advertising posts. But I’m sure you may have found an add-on to fix that. Let’s look at the bright side of it. First of all, you will be receiving quality contents from the community on whatever niche your website is about. One or more of those posts can lucky enough to rank on top of Google and you get more visitors. Forum can also be a great way to retain loyal readers. More & more people will come back and talk with others, etc.

What are the best plugins to create a Forum on WordPress

Vbulletin (commercial forum script) or phpBB doesn’t seems like a bad software at all except the fact that they’re PHP Scripts. You will have a hard time managing your blog and the forum because they both run on a whole different system. That’s why we do not recommend you use them along with WordPress.

But there is no need to get stuck in the hassle of coding as building  WordPress forum in not dependent on PHP Scripts, there are many plugins which can do this favor to create a WordPress forum using easy plugins without writing a single code. So let’s get started with the best ones for creating a forum on WordPress without PHP Scripts:

1. DW Question & Answer

dw-question-answer-1

If you are looking for a question & answer plugin for WordPress I think you just found one. ‘DW Question & Answer’ is small, neat, and has all the basic features that should be included. With a little of coding, you can quickly turn it into a forum.

2. WP Symposium

wp-symposium-plugin

While bbPress‘s main job is to create a simple forum then WP Symposium can help you do more than that, it can help you make a small social network with features like creating groups, creating level, messaging & chatting, email, inbox and many other functions. Currently it has 2 packages, free & paid.

What about you?

Which forum plugin are you using on your WP site. Do you think that these 2 plugins  worth a try? We also wanted to included bbPress too but didn’t because it’s too well-known.

what is plugin in wordpress, What is a WordPress Plugin and How to Develop it, WordPress Plugin

What is a WordPress Plugin and How to Develop it?

WordPress is a flexible platform which provides developer to add extra functionality without changing the core of WordPress. To enhance the functionality of WordPress we need to write custom plugins. WordPress Plugins are just like add-ons, which uses the core functionality of WordPress and add custom functionality into it.

In this article, we will look at what are WordPress plugins and how we can create one.

What is a Plugin in WordPress?

A plugin is a piece of custom code that extends the functionality of WordPress which already exists. It could be a single line of code or a bunch of lines.

What is a Plugin in WordPress

Why use a WordPress plugin?

Whenever you get a burger from a fast-food restaurant, you will be asked ” Sir, do you want extra cheese in your burger?

Why extra cheese in a burger? Of course, it will enhance the taste of your burger but it is not necessary. You can have your burger without adding cheese to it.

WordPress is your burger, and a plugin is your cheese that will add new functionality or enhance the basic functionality of your WordPress.

Plugin Behavior

There are two types of basic plugin behaviors

  1. add_action()
  2. add_filter()

add_action() and add_filter() both are WordPress hooks, to know more about hooks there is a complete tutorial for you on Some useful hooks in WordPress.

You want to perform some specific action using “add_action()” when:

  • A post is made

  • A post of a specific category is made

  • If a specific word occurs in the title of a post

  • If a new user added to a  particular group of users, like admins group, editors group

And the list goes on, depending on your requirements.

Let’s come to the presentation side. You want to perform some action using “add_filter()” when:

  • A post is presented(rendered) on the page

  • A post of a specific category is presented(rendered) on the page

  • If a specific word occurs in the title of a post

Practical example for add_action().

We will make a plugin that will fetch a list of email addresses of the subscribers from the database and send a notification email to each user having a link to that newly published post whenever a new post will be published

Open a text editor and put this code snippet in the file and save it with any name in the ‘wordpress\wp-content\plugins’ directory.

<?php

add_action(‘publish_post’, ‘notify’);

function notify(){

echo ‘Notified';

}

?>

Job has been done.  You have successfully created your new plugin. Go to the admin dashboard move the mouse over the plugins option and click on ‘installed plugin’ and see your plugin is coming in the list. What? It is not coming. Ok, no problem. Let’s tell WordPress about our plugin so that WordPress can know about it.

Open your plugin file and put these commented lines at the start of the file

/*

Plugin Name: My Notify Plugin
Description: With this plugin, you can notify a group of users about the publishing of a new post
Author: WpBrigade
Email: [email protected]
Version: 1.0

*/

So now your plugin file should look like this.

<?php

/*

Plugin Name: My Notify Plugin
Description: With this plugin, you can notify a group of users about the publishing of a new post
Author: WpBrigade
Email: [email protected]
Version: 1.0

*/

 add_action(‘publish_post’, ‘notify’);

function notify(){

echo 'Notified';

}

?>

 “publish_post” is a WordPress built-in function(hook) which is called when a post is to be published and what we are doing, we are telling the WordPress that when you call the “publish_post” function call our function also inside you “publish_post” function. This is called a hook. Like you don’t go and touch the core function and enhance that function in your own way.

Example for “add_filter()”.

Open your text editor again and put this code snippet into it.

<?php

/*

Plugin Name: Change Post Title
Description: With this plugin, you can change the titles of the post
Author: WpBrigade
Email: [email protected]
Version: 1.0

*/

 add_filter(‘the_title’, ‘add_text_to_post_title’);

 function add_text_to_post_title($title){

return $title. ‘ “Added when rendered”‘;

}

?>

“the_title” is also a WordPress hook and we are doing the same thing with it what we have done with the “publish_post” hook.

Again, keep the file and folder name the same, and put the plugin folder into the plugins directory.

So this was a little about how to enhance WordPress functionality, and plugins don’t stop here, you can create plugins to add new functionality to WordPress.

velocity page plugin

VelocityPage: Edit Your WordPress Posts Directly From Home Page

What would you do if your posts are outdated and need to be re-write or update? Of course you would go to the WordPress Dashboard then navigate to each post and do so, but that will be a waste of time though. To help you find a better solution we have found a WordPress plugin called Front-end Editor that allows you to edit WordPress posts right from the homepage. You do not have to go anywhere else.

why-buy-velocity-page-plugin

Edit WordPress Posts & Widgets on Homepage with Front-end Editor

As you can see above, I can easily re-title my post and once I’m done I can just hit Save. Same thing go to the content of the post. In order for the “Edit” button to appear you must can drag your mouse to the section you want to edit. The good thing about this is that it won’t overide any coding structure. In other words, this plugin is compatible with any WordPress themes.

Beside doing the main job which is letting us edit the articles, you can also change the Widget title or even its options without having to access the Admin Panel. If you do not like this functionality, you can enable or disable it.

That is it! I hope that from now on you can say good-bye to the Dashboard and still be able to fix mistakes on your posts without the need to go in there. If you are not happy with this plugin because it doesn’t contain the features you required, please try out VelocityPage. With it, you can insert shortcode, images, HTML, and even more editing options all from the front-end.

WordPress, WordPress development agency

How to Add Styled Single Post Navigation to Genesis

Beside having related posts under each articles to keeps your visitors staying at your site longer, we could also use the next / previous navigation feature that were built right into the Genesis already. What it does is that it will have 2 text right next to each other but not that close though and under it will be your latest post and then the post before that. It could look something like this.

post-navigation-for-genesis

You see, something like that will not help you generate more pageviews and lower down the percentage of bounce rate. We’ve got to do something more creative so that it can capture the attention of readers. How about a 2 arrows (next and previous posts) on each side of the page.

That’s nice right? As you scroll down the page, it will also follow you. I can guarantee that most people will click to find out what the pointing is all about. This styled navigation can easily be added into any Genesis Child Themes with a plugin called Genesis Single Post Navigation by Arne Brachhold. Even though I recommended you not to install much plugins especially just for customizing purposes, this one is necessary because it’s useful but also a lightweight plugin.

Let’s add it into WordPress…

First you will need to visit the plugin page to download or you can go straight to Plugins > Add New and then install it there. Done! Yeah I’m serious, there is no more steps for this except you need to activate the plugin but I’m sure you already done so. To see if the new post navigation is working correctly, just click on a random post.

I hoped that this short tutorial has helped you to install a brand new fancy navigation in every single posts to keep readers active on your site as much as possible.