Skip to content

Instantly share code, notes, and snippets.

@tkc49
Created November 8, 2014 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkc49/881ad66446c51dc7d226 to your computer and use it in GitHub Desktop.
Save tkc49/881ad66446c51dc7d226 to your computer and use it in GitHub Desktop.
RewriteAPIのサンプルソースです。 【管理画面】→【表示設定】→投稿ページ:ブログ(slug:blog)にした時に本来、URLが http://xxxx/blog となるのを http://xxxx/contents-list/reading/blog で投稿一覧を表示するサンプルです。
function myposttype_rewrite() {
global $wp_rewrite;
add_rewrite_rule(
'contents-list/reading/blog',
'index.php?pagename=blog',
'top'
);
}
add_action('init', 'myposttype_rewrite');
function my_page_link($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = get_post($id);
if ( is_wp_error( $post ) )
return $post;
$blog = get_option( 'page_for_posts' );
if( $id == $blog ){
// http://xxxx/blog を http://xxxx/contens-list/reading/blog に置換する処理
}
return $post_link;
}
add_filter('page_link', 'my_page_link', 1, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment