In WordPress I am using both the_permalink() and get_permalink() functions, but I cannot get any difference in the output of both functions. What is the difference between both functions?

3 s
3

the_permalink echos out the permalink of the current post to the frontend.

get_permalink however returns it as a variable, but does not echo it out. You can also pass a post ID to it if you want the permalink of another post.

the_permalink is equivalent to:

echo get_permalink();

Which is very close to what it actually does. This is the implementation of the_permalink:

function the_permalink() {
    echo esc_url( apply_filters( 'the_permalink', get_permalink() ) );
}

Leave a Reply

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