Zackery Fretty

Web, Android, IT, Whatever.

  • Zackery Fretty

  • Home
  • Blog
    • Apple
    • Android
    • Google
    • Raspberry Pi
    • WordPress
  • About
    • Mini Bio
      • Portfolio
    • Résumé
    • Portfolio
  • Contact

Author Archives: Zackery Fretty

About Zackery Fretty

Zackery is a project manager who loves everything about the Internet. Learn more about+Zackery Fretty

Fix “Missed Schedule” in WordPress by Using Linux Cron for your WP-Cron Tasks.

Posted by Zackery Fretty on May 3, 2013

Have you ever been working with a WordPress site and found things labeled as “Missed Schedule” or had various scheduled tasks be incredibly late/delayed when they were supposed to be set to run/post/whatever at X time in WordPress? That’s probably because wp-cron isn’t using the proper linux cron to set these tasks to work. It’s a “pseudo-cron” service which means while it functions a lot like cron–it’s not cron like you’d see in Linux, Mac, or Unix. It’s actually a far less reliable system to be using.

With cron you can set specific scripts, commands, and other tasks to run in your operating system at specific intervals of time, be it every 5 mins, every month, or every year as long as your operating system is up and running the job will be ran at the interval specified in cron. Most automated tasks in Unix based operating systems work with cron. The difference with “pseudo-cron” is that it doesn’t run independently. It requires something to trigger it, before it can trigger the events it has in its Queue.

With WordPress that “trigger” is someone visiting the website. Someone actually has to pull up your WordPress website in order for anything in wp-cron.php to run. So if you have a post set to go out on May 15th and no one visits the website until May 17th you’ll find yourself with a “Missed Schedule” error in WordPress.

I’m sure you can see where this quickly becomes a much less reliable solution than the standard linux cron, especially if your website is a low to medium traffic website that doesn’t get hits every day.

Thankfully you can configure your server to manage your wp-cron tasks automatically using the proper cron vs the pseudo-cron service built into WordPress.

Here is how you’d do that…. (with cPanel anyways)

First we have to disable cron within WordPress, since we will no longer be using it. To do that simply open your wp-config.php file and drop in the following line:

define('DISABLE_WP_CRON', true);

Next we will want to open up your cPanel account and locate the Cron Jobs tab as shown below:

Screen Shot 2013 05 03 at 2.46.50 AM Fix Missed Schedule in WordPress by Using Linux Cron for your WP Cron Tasks.

Once inside of the Cron Jobs tab you’ll have the following screen:

Screen Shot 2013 05 03 at 2.50.32 AM Fix Missed Schedule in WordPress by Using Linux Cron for your WP Cron Tasks.

Under Common Settings select Run Every 5 Minutes and then enter the following command (replacing zackeryfretty.com with your own domain) in the Command section:

wget -O /dev/null http://www.zackeryfretty.com/wp-cron.php

What this will do is trigger the wp-cron.php file every 5 minutes automatically–even if someone doesn’t visit your website. So this means rather than relying on a random visitor to trigger your cron service with WordPress, you’ll have 100% accuracy in all scheduled tasks within a 5 minute window.

That’s it, congrats you just fixed the pesky “Missed Schedule” error in WordPress and made scheduled tasks in WordPress just much more reliable and awesome in general.

Posted in Linux, WordPress

Setting your “Featured Image” as the Facebook Image — No Plugins.

Posted by Zackery Fretty on March 11, 2013

There are a bunch of plugins out in the wild that will help you do this, but, plugins are silly when it is something as simple as this. Essentially all you are trying to do to force an image to show up on Facebook is add the following open graph meta tag to the <head> of your source:

<meta property="og:image" content="URL-TO-YOUR-IMG.PNG">

So, no real need to do a plugin for this, you can easily make a nice little PHP call to find the URL of your featured from your WordPress Page/Post (this works on both) and slap it into that content=”" area automatically. It looks a little something like the following:

<?php if (has_post_thumbnail( $post->ID ) ): ?>

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>

<?php echo $image[0]; ?><?php endif; ?>

What that little snippet does is just find the URL of your Featured Image and then echo’s it out, which is fairly simple but it exactly what we need for this situation.

Now all you want to do is drop that into the content=”" of the Facebook Image meta tag, I prefer to drop it all on one line myself like so:

<meta property="og:image" content="<?php if (has_post_thumbnail( $post->ID ) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?><?php echo $image[0]; ?><?php endif; ?>" />

You’ll want to put that before your <head> tag closes, so, open up our head.php, header.php, or something like that (it’s different from theme to theme) just do a quick search for </head> and put this right above that.

Hit save, and boom featured images are now your default Facebook share images on all of your pages and posts.

Posted in WordPress
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • …
  • 21
  • »