0

How to Change The Default slug shortlink “/?p=” base in WordPress?

https://site.ltd/?p=115756
to

https://site.ltd/post/115756/
or
https://site.ltd/115756

Please provide the function code

1
  • 1
    You don't need code to do this, it can be done in the admin permalinks settings page
    – Tom J Nowell
    Commented Aug 16, 2021 at 0:39

2 Answers 2

2

Go to Settings->Permalinks and set a custom structure as:

/post/%post_id% or just /%post_id%

0
-1

I have written a snippet myself that I think it's what u need.

You need to active and replace for example x.com/?p=100 with x.com/100

so this would help u:

add_action('wp', function() {
    $term = substr($_SERVER['REQUEST_URI'], 1);
    
    if ( is_numeric( $term ) )
        wp_redirect(get_permalink($term));
});

Regards

2
  • This code will process /100 but it won't help the site generate that I don't think.
    – Rup
    Commented Jul 19, 2023 at 14:43
  • I use this on my big website. The problem has been begun when we send the query string URL in sms and some of our clients received it as un-linked. the problem was the question mark. so we had to implement a URL without a question mark. this is work and all are ok with that.
    – Saeed
    Commented Jul 19, 2023 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.