-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunmus_rewrite.php
69 lines (56 loc) · 1.79 KB
/
unmus_rewrite.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Rewrites
*
* @package unmus
*/
// Security: Stops code execution if WordPress is not loaded
if (!defined('ABSPATH')) { exit; }
/**
* Remove Custom Post Type Slug from Permalink
*
* Standard Permalink:
* https://www.unmus.de/cpt-slug/post-slug/
*
* Target is to have an URL as the following for all posts.
* https://www.unmus.de/post-slug/
*
* Format Zimtwolke requires a special routine as CPT Name is different (Ello).
* CPT Episode is handled by the podlove plugin.
*
* @param string $post_link Permalink
* @param WP_Post $post Post
* @param book $leavename Wheter to keep the post?
*/
function unmus_remove_cpt_slug_from_perma( $post_link, $post, $leavename ) {
$custom_post_types = array( 'pinseldisko', 'ello', 'podcast', 'raketenstaub' );
// No Action required for Standard Post Type
if ( ! in_array( $post->post_type, $custom_post_types ) || 'publish' != $post->post_status ) {
return $post_link;
}
if(stristr($post_link, 'zimtwolke') === FALSE) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
else {
$post_link = str_replace( '/zimtwolke/', '/', $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'unmus_remove_cpt_slug_from_perma', 10, 3 );
/**
* Enable Parsing of Custom Post Types URLs
*
* Custom Post Type URLs are not working without this function.
* But I do remember why this is required exactly.
*
* @param WP_Query The WP_Query Instance
*/
function unmus_enable_parsing_cpt_urls( $query ) {
if ( ! $query->is_main_query() )
return;
if ( ! empty( $query->query['name'] ) ) {
$query->set( 'post_type', array( 'post', 'page', 'pinseldisko', 'ello', 'podcast', 'raketenstaub' ) );
}
}
add_action( 'pre_get_posts', 'unmus_enable_parsing_cpt_urls');
?>