Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created April 15, 2012 09:16
Show Gist options
  • Save evansolomon/2391430 to your computer and use it in GitHub Desktop.
Save evansolomon/2391430 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Kindle Book auto-tags
License: GPLv2 or later
*/
function kindle_book_auto_tagger( $post_id, $post ) {
// Check for the string with our tags
// Example string: "Customer tags: suspense, kindle free book, science fiction, post-apocalypse, fantasy."
$regex = '/customer tags: ?(.+)\./i';
preg_match( $regex, $post->post_content, $kindle_tags );
// Make sure we found tags to use
if( ! $kindle_tags )
return;
// Set the tags
wp_set_post_tags( $post_id, $kindle_tags[1], true );
}
add_action( 'publish_post', 'kindle_book_auto_tagger', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment