$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>shortlink - Custom short url for wordpress post|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

shortlink - Custom short url for wordpress post

matteradmin8PV0评论

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' );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far