我编写了社交分享按钮,我想在其中将 single.php 模板中的当前帖子链接到社交媒体分享链接。
当我附加永久链接以共享 url 时出现问题,它没有给出帖子的完整 url:
我试过了 http://twitter.com/share?url=<?php the_permalink() ?>
但只给出了 /post/69
的输出不是 http://example.com/post/69
.
有什么建议吗?
最佳答案
在 post 循环之外,您可以为此使用 wordpress get_permalink()
函数。在循环中,您可以使用 the_permalink($post->ID)
尽管这会直接呼应 url。这是来自 wordpress.org 的引用。
https://developer.wordpress.org/reference/functions/get_permalink/ https://codex.wordpress.org/Function_Reference/the_permalink
关于php - Wordpress:回显当前帖子永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34789792/