shortlink - Custom short url for wordpress post

admin2025-06-02  3

How can I display a short url of the post in the content arrea like

Shortlink - 

instead of the standard

Shortlink - /?p=1234

WITHOUT USING ANY PLUGINS or other services like bitly

How can I display a short url of the post in the content arrea like

Shortlink - https://www.example/abc24g4

instead of the standard

Shortlink - http://example/?p=1234

WITHOUT USING ANY PLUGINS or other services like bitly

Share Improve this question asked Feb 23, 2019 at 3:38 user159405user159405
Add a comment  | 

2 Answers 2

Reset to default 0

Without a plugin or service? You can't. There's no such thing.

From the documentation for wp_get_shortlink() (emphasis mine):

This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts. Plugins can short-circuit this function via the ‘pre_get_shortlink’ filter or filter the output via the ‘get_shortlink’ filter.

Not sure of what you are trying to accomplish.

Sounds like you want to show the "shortlink" of the current post in the current post contents.

Create a shortcode (code below) and add to your templates functions.php file, then add [show_current_page_url] some where in the post contents to display the url.

function show_permalink_for_post( $atts ){

        // this gets the current page or posts permalink
        $link = get_permalink(get_the_ID());

        return $link;
}
add_shortcode( 'show_current_page_url', 'show_permalink_for_post' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748873791a314432.html

最新回复(0)