Back to Top Disable Autosave in Wordpress

Contact: burt (AT) islandcolors (DOT) com | 415.704.1832

Disable Autosave in WordPress

To Autosave or Not

Wordpress has an autosave feature that will automatically save your content every 60 seconds. If you have ever made a big mistake while working on a post or article, autosave can be your White Knight saving you from hours of re-typing.  

The problem arises if you have a lot of content that becomes malformed when it is saved in the editors visual mode. This content can be blocks of code, embedded in videos, even those pesky paragraph tags that

Adjust the Autosave Interval

There is no simple directive to turn off the WordPress autosave. You can change its interval from the standard 60 seconds to whatever you would like by simply putting the following directive in the wp-config.php file found in your WordPress root folder:

define('AUTOSAVE_INTERVAL', 360 );  // seconds

If you want to basically turn off autosave you can increase the Interval to some very high number. The other option is creating your own plugin.

Turn Off Autosave Altogether

Create a Simple Plugin

To just turn autosave off or disable it, you create your own simple 5 line plugin. To accomplish this you need to create a text file with the name of say turn-off-autosave.php. The next step you will copy the following code into this text file.


Thirdly, you will take this text file and place it in your WordPress plugin folder which is found inside the wp-content folder. Lastly, you will then activate this plugin by finding the name ‘Turn off Autosave’ in the inactive plugin list.

That is it.

iPad Layout CSS – Fix Using Viewport Meta Tag

How to Fix the Right Side Gap in an iPad

When the Striking Theme was upgrade to Version 3.05, the theme layout broke in the iPad  Mobile Safari and Firefox.

Renders Left Justified

By broke, I mean the layout was not centered in the viewport of the iPad. It acts as if it was left-justified causing s a slight gap on the right-side margin.

There is a CSS Fix

Yes, there is a CSS fix, but this may require putting an extra wrapper around the code and setting the body tag margins to auto. You can follow the thread here on Webmaster World or here at Stackoverflow

A Simpler Better Way

Use the Viewport Meta Tag

Yes, by using one of the new Safari browser directives – that Firefox mobile is supporting too.  ALL you have to do is put the following somewhere in between the <head> and </head> in your template


For those of you using WordPress, insert the following in your function.php file

//////////////////////////////////////////////
/// Add the /viewport meta to the header
/////////////////////////////////////////////
add_action('wp_head', 'add_viewport_meta');

function add_viewport_meta() {
       echo "\n" . '' . "\n";
}

Follow this link for page full of More Striking Theme WordPress Tips

Jquery Code Snippets

My Favorite Jquery Code Snippets

The Web is a great place to find jQuery code snippets. It is truly amazing what some simple  searches with Google will turn up. In the past I often find myself putting these jQuery code snippets or other bits of information in Gmail and then tagging them in the subject area.

Gmail, just wasn’t made for this function, even though there was lots and lots of free space to store content in. I recently found a better way using Evernote – see the bottom of this page for more details

The following are some of those handy bits of jQuery code  snippets that I have in one of my Evernote notebooks.

jQuery Snippets

[toggle_content title="Open Prettyphotos on load"]

jQuery(document).ready(function($){
   // show a Youtube Video
    $.prettyPhoto.open('http://www.youtube.com/watch?v=hNDUNsBKSos', '', 'Click anywhere to skip intro...');
  // 1 second equals 1000 milliseconds movie is 15 seconds this works at 26400
    setTimeout("$.prettyPhoto.close()", 26400);
    });

[/toggle_content]
[toggle_content title="jQuery Delay like PHP Sleep"]

jQuery(document).ready(function($){
   $('.top_slide').slideUp(500).delay(700).fadeIn(400);
});

[/toggle_content]

[toggle_content title="Add Stripes to Table"]

jQuery(document).ready(function($){
      // Every other element will be selected
      // CSS would be  background: grey;
       $("tr:odd").addClass("odd");
    });

[/toggle_content]
[toggle_content title="Make HTML5 Work in IE"]

[/toggle_content]
[toggle_content title="Correctly Enqueue jQuery in WordPress"]

function my_jquery() {
    // don't replace WordPress admin jQuery
if( !is_admin()){
        // get rid of old jQuery
   wp_deregister_script('jquery');
       // Register new one using google libs
   wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"), false, '1.6.1');
      // Enqueue new jQuery Script
   wp_enqueue_script('jquery');
}}
     // Add this WordPress action to init
     // NOT in wp_head !!!
    // anywhere else can cause problems
add_action('init','my_jquery');

[/toggle_content]
[toggle_content title="Ajax Load - No Iframe"]

$(document).ready(function(){
      $("#no_iframe").load("http://islandcolors.com/jquery-tips");
});

[/toggle_content]
[toggle_content title="Ajax Load - Fade In Fade Out Every 35 Seconds"]

$(document).ready(function(){
      $("#no_iframe").fadeOut('slow').load("http://islandcolors.com./jquery-tips").fadeIn('slow');
}, 45000);

[/toggle_content]

Have You Tired Evernote?
Evernote the life saver

EverNote

Searching for the information in Gmail with your homegrown Subject line tagging system is problematic , especially if you are using the native email client found on  the iPad.

But, there is another way and that is with Evernote . What is nice about Evernote is that you can find it as an App on almost every mobile client that you could use - even Blackberry.  

Does Evernote Work with Microsoft Mobile 7?

I just love that question. The question used to be 'Does it work with Mac OS ?' - Yes it does. And with ALL Mac devices. Than you very much.

I  don't know if it does work on Microsoft's Mobile 7 and who cares anyway? - Well, yes it does work on Windows and Windows Mobile, but not Mobile 7.

Evernote is just a great way to capture everything; from web pages, iPhone photographs, scanned pieces of paper and pictures to verbal notes.

Limit or Disable WordPress Post Revisions

WordPress Perfectionist Beware

WordPress Revisions

Getting your WordPress  post just right takes a lot of time.

We all know that the editor has its quirks to say the least. By the time you have completed your 300 word article and then tweaked it for the 100th time you can end up with a lot of revisions.

If you are a perfectionist, you can have a very large database in no time. This can, in extreme circumstances, slow your site down.

Disable All Revisions

It is a shame  that WordPress out of the box doesn’t have a way to turn on or turn off post revisions, or at the very least limit the number of revisions that will occur for each post.

They Gave Us  ‘WP_REVISIONS’

Luckily, they have given us  the ability to do both of those functions  with the define(‘WP_POST_REVISIONS’), by either specifying ‘false’ or a number of revisions we want to keep for each post.

Use ‘false’ for No Revisions

//Disable the WordPress  revisions feature.
define('WP_POST_REVISIONS', false);

I Want 8 Revisions for Each Post

// Set the number of WordPress revisions
// Here we have 8
define('WP_POST_REVISIONS', 8);

Edit the wp-config.php File

Yes, sadly, you must access the wp-config.php file via FTP, and edit it with a text-editor. If you need to ask what is a text-editor and what is FTP, then I would advise not doing this. Find someone who can help you.

Step 1: Select wp-config.php

Using your trusty FTP program select the wp-config.php file – duplicate it first for insurance – and get it up into your text-editor. You should have no difficulty finding it.

Step2: Edit wp-config.php

Put it Where?

Once you have wp-config.php in your editor, you need to put the 

define( 'WP_POST_REVISIONS')

someplace. Don’t fret just look where there is a statement starting with define and put it on the line below it. Remember to put the ‘ ; ‘ at the end of the statement.

In the above example we are using ‘false’ to indicate we don’t want any revisions kept. If you do want revisions – but not an unlimited, database crushing  amount – set a number that makes sense to you. Remember you can always go back in and modify this number at a later date.

Once you save your wp-config.php file, you are finished for the day.

Deleting ALL those Revisions

A revision is  a WordPress built-in Post Type –

post_type = 'revision'

. Each revision is saved with all of the different types of post types in one big MySQL table. Deleting them is relatively simple but dangerous. Here is what the MySQL command looks like.

// Remember the 'wp_' is the standard WP prefix.
// Yours should be different than the standard 'wp_'
// for security purposes
DELETE FROM wp_posts WHERE post_type = 'revision';

Not too complicated, you say. You are correct, but you can really mess things up if you are not careful.

Ready for phpMyadmin?

If you have to ask “My php what“, then you are not ready. There is a way with the WP-DBmanager plugin to execute the MySQL command without having to use phpMyadmin.  Go ahead and install this Swiss Army Knife for managing your database – it has only been downloaded over 400,000 times, you think it might be good?

Backup, Backup and Backup

After  installing and activating WP-DBmanager,  backup your database before trying any of its many functions. Once you have completed the backup,  read deleting WordPress post revisions – Did I tell you to Backup your database?

If you are in a hurry, and don’t want to mess around with DELETE MySQL commands,  look at the box below for a ‘no risk way to delete all of those revisions’.

Did You Know:

Get Rid of Those Revisions Manually

Afraid of playing around with the DELETE MySQL Command?  Who could blame you?

There is a manual way to get rid of all those revisions without coming within a Texas mile of a MySQL command.

Insert the define(‘WP_POST_REVISIONS’, 5); into your wp-config.php file with the number of revisions you want to keep – say 5 as an example.

Next go to the Post edit main page and delete everything in your Trash.

Next click on Title and select all your posts on the page. Go to the ‘Bulk Actions’ drop down list and select ‘Move to Trash’. Click on ‘Apply’.

Do this until all your Post are in the Trash – of course you do have a fresh backup of your database don’t you?

Lastly, select ‘Trash’ and then click on Title to select all of your Trashed posts.

Select ‘Restore’ from the Bulk Actions drop down list and click on Apply.

Continue doing the process until all of your post are restored.

Now, everyone of your Post will have no more than 5 revisions

Striking Theme – Add a Meta Box to Multiple Custom Post

Multiple Custom Post Types

In a previous article I showed you how to add the Striking Theme‘s Shortcode Generator Meta box to an individual Custom Post Type – Can you believe all the WordPress jargon in this one sentence?

If you recall it was relatively simple using the

add_meta_box()

WordPress function:

 add_action('admin_menu', 'shortcode_gen_to_post_types');

function shortcode_gen_to_post_types () {
     add_meta_box(
       'shortcode',
       __('Shortcode Generator','striking_admin'),
      'theme_shortcode_generator_iframe',
      'actooltip',
      'normal',
      'high'
      );
       }

The

add_meta_box

can only be used for one Custom Post Type (CPT) at a time. If you had three CPTs – ‘profiles’, ‘movies’ and ‘lunch_meats’ – you would have to create a function for each one or chain multiple

add_meta_box()'s

together in one function.

A Trick Pony will Do That

Yes, our Trick ‘PHP’ Pony can do that by grabbing the values of a multidimensional array using the PHP

foreach

statement. A multidimensional array? Maybe chaining the

add_meta_box

is an easier way to do this.   You can learn a little about multidimensional arrays and the

foreach

statement if you want.

Step 1: Values You will need to Have

You will need the same values as were required for the Single Custom Post.

[list type="red"]

[li] The Metabox Name – ‘shortcode’ [/li]

[li] The Admin Name of the Metabox – _(‘Shortcode Generator’, ‘striking_admin’) [/li]

[li] The Metabox Function – ‘theme_shortcode_generator_iframe‘ [/li]

[li] The Custom Post Type Slug(s) – ‘profiles’, ‘movies’, ‘lunch_meats’ We will get Yours using the get_post_type() function [/li]

[li] The Metabox Location – ‘normal’ [/li]

[li] The Priority for the Metabox – ‘high’ [/li]

[/list]

We will replace ‘profiles’, ‘movies’, ‘lunch_meats’ with your CPT slugs, by selecting for  ’_builtin’ Custom Post Types equals false argument in get_post_types() .This array will get all of the Custom Post Types not created by WordPress.

Step 2: Copy and Paste

Yes, lets copy and paste the following into your function.php file – you will find this in the following WordPress directory wp-content/themes/striking/function.php.

add_action('admin_menu', 'shortcode_gen_to_post_types');

function shortcode_gen_to_post_types () {

//	add_meta_box(
//		'shortcode',
//		__('Shortcode Generator','striking_admin'),
//		'theme_shortcode_generator_iframe',
//		'[custom post type slug]', // you can only put one value here
//		'normal',
//		'high'
//		);

//
///  The page string does not accept an array we will use a foreach loop
///  to create mulitpe boxes
 $buitin = array('_builtin' => false,); //Get only non built-in CPT
 $post_names = get_post_types($buitin,'names'); //This will be the array of CPT names

$args = array(
    'id' => 'shortcode',
    'title' => __('Shortcode Generator','striking_admin'),
    'pages' => $post_names, //All of the non-builtin CPT are here
    'callback' => 'theme_shortcode_generator_iframe',
    'context' => 'normal',
    'priority' => 'high',
				);

foreach ($args['pages'] as $page) {
        add_meta_box($args['id'], $args['title'], $args['callback'], $page, $args['context'], $args['priority']);
    }
}

Step 3: We Love Get_Custom_Post_Types

Our Trick Pony is really doing its job with the get_custom_post_types()  _builtin=> false. We can  sit back and watch his moves and leave our brain in our pockets and not worry if we are missing any Custom Post Slugs.

Step 4: Start Using the Shortcode Generator

Now your Trick Pony should be working and you should have those nifty Striking Shortcodes available for your Custom Post Type and you should be making those incredible unique landing pages that will increase your ROI 100 fold.

I Want to Know:

Why did KaptinLIN design the Striking Theme with the shortcode generator in a metabox instead of in WSIWG Editor as an icon?

Maybe he is saving us from an upgrade nightmare when the next version of WordPress writes a complete makeover of the Editor?

This is A Form

Contact Me

We would love to hear from you! Please fill out this form and we will get in touch with you shortly.