Function Name: wp_get_shortlink
If you’re building a WordPress website, you’re probably familiar with permalinks. Permalinks are the permanent URLs to your individual pages and blog posts. However, sometimes you need a shorter URL that’s easier to share, such as on social media platforms. This is where wp_get_shortlink comes in.
wp_get_shortlink is a WordPress function that retrieves the shortlink for the current post or page. The shortlink is a shorter version of the permalink, which can be used in situations where a shorter URL is needed.
The function takes a single parameter, $id, which is an optional post ID. If no ID is provided, the function will use the ID of the current post or page.
Here’s an example usage code for wp_get_shortlink:
<?php $shortlink = wp_get_shortlink(); echo $shortlink; ?>
In this example, the function is called and the resulting shortlink is stored in the $shortlink variable. Finally, the shortlink is displayed using the echo statement.
By default, WordPress generates shortlinks using the wp_get_shortlink function. However, if you want to use a custom shortening service, you can use a plugin like Jetpack or a custom function to override the default behavior.