Custom Post Type Support
-
Great plugin! I love Hash IDs, and appreciate your taking the time to add them to permalinks.
I also wanted to use this plugin with a Custom Post Type, so I added the necessary code. I couldn’t find a Github repo, so the modification is shown below.
I’ve found this especially helpful when combined with Custom Post Type Permalinks.
Original:
wp-hashed-ids.php
lines18-26
at version1.0
function hashed_id() { global $wp_rewrite; add_rewrite_tag('%hashed_id%','([^/]+)'); $permalink = $wp_rewrite->permalink_structure; if (!empty($permalink) && false !== strpos( $permalink, '%hashed_id%' )) { add_filter('pre_post_link', '_hashed_id_post_link', 10, 2); add_filter('parse_request', '_hashed_id_parse_request'); } }
Modification:
// Add after line 23, 'pre_post_link' add_filter('post_type_link', '_hashed_id_post_link', 10, 2); // CPTs
Result:
function hashed_id() { global $wp_rewrite; add_rewrite_tag('%hashed_id%','([^/]+)'); $permalink = $wp_rewrite->permalink_structure; if (!empty($permalink) && false !== strpos( $permalink, '%hashed_id%' )) { add_filter('pre_post_link', '_hashed_id_post_link', 10, 2); // Posts add_filter('post_type_link', '_hashed_id_post_link', 10, 2); // CPTs add_filter('parse_request', '_hashed_id_parse_request'); } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Post Type Support’ is closed to new replies.