Why am I getting 404 after using category_link and post_link filters?


I want to customize the posts category and single permalinks. I’m doing something like this:

add_filter('post_link', 'set_post_links' , 10, 2);
function set_post_links($permalink, $post){
  if(is_wp_error($post) || empty($post->post_name)) return $permalink;
  return home_url(user_trailingslashit("news/$post->post_name"));

add_filter('category_link', 'lr_filter_category_link', 10, 2 );
function lr_filter_category_link( $termlink, $term_term_id ) {
  $term = get_term($term_term_id);
  return home_url(user_trailingslashit("news/$term->slug"));

Generated urls/links are correct, but when clicked they go to a 404 page. I already refreshed the permalinks from admin.

How to solve?

Luca Reghellin 1 month 0 Answers 11 views 0

Leave an answer