$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - Difference between the_permalink() and get_permalink() function|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - Difference between the_permalink() and get_permalink() function

matteradmin8PV0评论

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?

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?

Share Improve this question edited Jun 27, 2014 at 16:24 Peter Mortensen 2682 silver badges10 bronze badges asked Jun 27, 2014 at 11:36 AliasgerSWAliasgerSW 1531 gold badge2 silver badges8 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 23

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() ) );
}

If you look at the WordPress Codex on this you will see that get_permalink() is there for use outside the loop. the_permalink() is for use within the loop. That’s the easiest way to look at it.

the_permalink() is used in posts loops, like the_title(). Read more about loops in The Loop.

get_permalink() can be used in loops or outside the loops. In the loops, the function returns (not echo) the current post permalink. But outside loops, it requires a post ID.

For example:

echo get_permalink( 1 );

This will display the current page permalink:

echo get_permalink();
Post a comment

comment list (0)

  1. No comments so far