Home  >  Q&A  >  body text

How to use get_permalink function in WordPress to get the current page URL, including query string?

<p>I'm trying to use the get_permalink function to display the current post/page URL on the frontend. The following code runs fine but does not print the query string. How to display the full URL including the query string? </p> <pre class="brush:php;toolbar:false;">// Short code: [current-url] function current_url() { return get_permalink($post->ID); } add_shortcode( 'current-url', 'current_url' ); ```</pre></p>
P粉404539732P粉404539732388 days ago507

reply all(1)I'll reply

  • P粉613735289

    P粉6137352892023-08-31 10:59:39

    use this code for it

    function current_url() {
    global $wp;
    echo home_url( $wp->request );
    }
    add_shortcode( 'current-url', 'current_url' );

    reply
    0
  • Cancelreply