Skip to content

Instantly share code, notes, and snippets.

@andxbes
Last active August 27, 2023 08:08
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 andxbes/7da566fae98369b872bfd66031accb2c to your computer and use it in GitHub Desktop.
Save andxbes/7da566fae98369b872bfd66031accb2c to your computer and use it in GitHub Desktop.
rewrite_blog.php
<?php
add_action('init', function () {
add_rewrite_rule('insights/([^/]+)/([^/]+)/?$', 'index.php?category_name=$matches[1]&name=$matches[2]&post_type=post', 'top');
add_rewrite_rule('lp/([^/]+)/?$', 'index.php?name=$matches[1]&post_type=e-landing-page', 'top');
});
add_filter('pre_post_link', function ($permalink, $post, $leavename) {
if ($post->post_type === 'post') {
$permalink = '/insights' . $permalink;
}
return $permalink;
}, 99, 3);
add_filter('post_type_link', function ($post_link, $post, $leavename) {
if ('e-landing-page' === $post->post_type) {
$post_link = get_home_url() . '/lp/' . $post->post_name . '/';
}
return $post_link;
}, 12, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment