Monday, October 24, 2022
HomeWordPress DevelopmentCustomized Permalink Construction For a Particular Class

Customized Permalink Construction For a Particular Class


Good day i needed to attain customized permalink for information class and that is my code however its getting 404
The url is displaying precisely as i needed however the url isn’t redirecting to that particular submit.

Desired Permalink Construction is

/%class%/%postname%/%post_id%/

CODE HERE

    //Rewrite URLs for "testimonial" class
add_filter( 'post_link', 'custom_permalink', 10, 3 );
operate custom_permalink( $permalink, $submit, $leavename ) {
    // Get the class for the submit
    $class = get_the_category($post->ID);
    if (  !empty($class) && $class[0]->cat_name == "Information" ) {
        $cat_name = strtolower($class[0]->cat_name);
        $permalink = trailingslashit( home_url("https://wordpress.stackexchange.com/". $cat_name . "https://wordpress.stackexchange.com/" . $post->post_name . "https://wordpress.stackexchange.com/" . $post->ID ."https://wordpress.stackexchange.com/" ) );
    }
    return $permalink;
}

add_action( 'init', 'custom_rewrite_rules' );
operate custom_rewrite_rules() {
    add_rewrite_rule(
        'information/([^/]+)(?:/([0-9]+))?/?$',
        'index.php?category_name=information&identify=$matches[1]&web page=$matches[2]',
        'prime' // The rule place; both 'prime' or 'backside' (default).
    );
}

Please Assist

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments