Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @alprio,

    Unfortunately, there is no out-of-box solution available. A few years ago I prepared a custom snippet that should do exactly what you are trying to do. Here is the code:

    function pm_force_404_on_native_permalinks() {
    global $wp_query, $pm_query, $permalink_manager_uris;

    // 1. Get the queried object
    $object = get_queried_object();

    // 2. Use it only if no custom permalink is detected
    if ( ! empty( $pm_query['id'] ) ) {
    return;
    }

    // 3. Check if the custom permalink exists for requested item
    if ( ! empty( $object->post_type ) ) {
    $has_custom_uri = $permalink_manager_uris[ $object->ID ];
    }

    // 4. Force "404" error page
    if ( ! empty( $has_custom_uri ) ) {
    $wp_query->query = $wp_query->queried_object = $wp_query->queried_object_id = null;
    $wp_query->set_404();
    status_header( 404 );
    nocache_headers();
    $pm_query = '';

    // Disable canonical redirect
    remove_action( 'template_redirect', 'wp_old_slug_redirect' );
    remove_action( 'template_redirect', 'redirect_canonical' );
    }
    }
    add_action( 'wp', 'pm_force_404_on_native_permalinks', 5 );
    Thread Starter alprio

    (@alprio)

    Hello again ,

    Thank you for the snippet.
    I did some tests and it seems that is working correctly for products.
    is it possible to expand this snippet for /product-category/ slug too ?

    Plugin Author Maciej Bis

    (@mbis)

    Hi @alprio,

    Yes, as this requires Pro version to work, please send the support request with your license key here:
    https://permalinkmanager.pro/contact/

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.