• Resolved dekazo

    (@dekazo)


    I added the following to functions.php to remove the category from the URL.
    The URL is now what you want.

    function remcat_function($link) {
    return str_replace(“/category/”, “/”, $link);
    }
    add_filter(‘user_trailingslashit’, ‘remcat_function’);
    function remcat_flush_rules() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }
    add_action(‘init’, ‘remcat_flush_rules’);
    function remcat_rewrite($wp_rewrite) {
    $new_rules = array(‘(.+)/page/(.+)/?’ => ‘index.php?category_name=’.$wp_rewrite->preg_index(1).’&paged=’.$wp_rewrite->preg_index(2));
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }
    add_filter(‘generate_rewrite_rules’, ‘remcat_rewrite’);

    If you check the Query Monitor, it will be as follows.

    View post on imgur.com

    Should this be fixed?
    Is there any good way to fix it?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    You shouldn’t flush rewrite rules on every page load, it’s an expensive operation. Flush them when your plugin is activated, deactivated, or an option is updated, etc.

    Thread Starter dekazo

    (@dekazo)

    Hello.
    Thank you very much for contacting me.

    I did some research.
    I found out that it was bad code.

    Instead, I did the following:

    add_filter(‘bcn_breadcrumb_url’, ‘my_breadcrumb_url_changer’, 3, 10);
    function my_breadcrumb_url_changer($url, $type, $id)
    {
    if(in_array(‘category’, $type))
    {
    $url = str_replace(“category/”, “”, $url);
    }
    return $url;
    }

    Thread Starter dekazo

    (@dekazo)

    Excuse me. I posted it by mistake. Please ignore it.
    This case has been resolved.

    • This reply was modified 4 years ago by dekazo.
    • This reply was modified 4 years ago by dekazo.
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘About NON-SELECT alerts’ is closed to new replies.