Created
November 13, 2014 15:57
-
-
Save sideshowcoder/6c57a8fa85c28e9a837b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Functions to handle transition from Tumblr to Wordpress | |
| * author: philipp fehre <philipp@fehre.co.uk | |
| * | |
| * The goal ist to make imported tumbler posts work along the normal permalinks | |
| * generated by tumblr | |
| * | |
| * This works for posts imported via http://tumblr2wordpress.benapps.net | |
| * exported file containing the tumblr post ids in the post_name field. | |
| */ | |
| add_action('init', 'tumblr_add_rewrite_rules'); | |
| function tumblr_add_rewrite_rules() { | |
| global $wp_rewrite; | |
| $wp_rewrite->add_rewrite_tag('%tumblrslug%', '([^/]+)', ''); | |
| $wp_rewrite->add_permastruct('tumblrslug', '%tumblrslug%', false); | |
| } | |
| add_filter('post_link', 'tumblr_permalinks', 10, 3); | |
| function tumblr_permalinks($permalink, $post, $leavename) { | |
| $post_name = $post->post_name; | |
| if ( is_numeric($post_name) ) { | |
| // this is a tumblr imported post, we need to attach the slug | |
| // so the post_name contains the tumblr post id | |
| $tumblr_slug = sanitize_title($post->post_title); | |
| } else { | |
| // this is not a tumblr post so just remove the slug | |
| $tumblr_slug = ''; | |
| } | |
| $permalink = str_replace('%tumblrslug%', $tumblr_slug, $permalink); | |
| return $permalink; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment