To get the post page URL in WordPress by using code, you can use the get_permalink()
function. This function returns the full permalink for the current post or post ID.
To use the get_permalink()
function, simply pass in the post ID. You can get the post ID using the get_the_ID()
function.
For example, the following code will return the permalink for the current post:
$post_permalink = get_permalink( get_the_ID() );
You can also use the get_permalink()
function to get the permalink for a specific post ID. For example, the following code will return the permalink for the post with the ID of 123:
$post_permalink = get_permalink( 123 );
Once you have the post permalink, you can use it however you like. For example, you could display it in a post template, or you could use it in a link.
Here is an example of how to display the post permalink in a post template:
<a href="<?php echo get_permalink( get_the_ID() ); ?>"><?php the_title(); ?></a>
This code will generate a link to the post with the current post title.
I hope this helps!
Comments