How to use get_permalink function in WordPress to get the current page URL, including query string?
P粉404539732
P粉404539732 2023-08-30 17:13:25
0
1
586
<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粉404539732
P粉404539732

reply all(1)
P粉613735289

use this code for it

function current_url() {
global $wp;
echo home_url( $wp->request );
}
add_shortcode( 'current-url', 'current_url' );
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template