WordPress

Get Post Page URL in WordPress

0
WordPress

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:

PHP
$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:

PHP
$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:

PHP
<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!

Create Custom Post Type in WordPress

Previous article

Remove Comment Form in WordPress Single Post

Next article

You may also like

Comments

Leave a reply

Your email address will not be published. Required fields are marked *

More in WordPress