简体   繁体   English

广告插入器块内的 WordPress get_permalink() 不起作用

[英]WordPress get_permalink() inside Ad Inserter block not working

<?php 
  // query db once for permalink
  $permalink = urlencode(get_permalink());
?>

<a href='https://www.facebook.com/sharer/sharer.php?u=<?php echo $permalink; ?>' onclick='javascript:return (function(){window.open("https://www.facebook.com/sharer/sharer.php?u=<?php echo $permalink; ?>", "MsgWindow", "width=600, height=600, scrollbars=yes", false); return false;})();'>
<img onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'" style="margin-right:5px; width:40px; height:40px" src="data:image/png;base64,..." alt="Facebook Share" />
</a>

The above code executes in an Ad Inserter block but returns the wrong permalink.上面的代码在 Ad Inserter 块中执行,但返回错误的永久链接。 I have no other plugins installed for debugging purposes so that means no caching enabled.我没有为调试目的安装其他插件,这意味着没有启用缓存。

The code executes w/o error but doesn't return the correct URL.代码执行无错误,但未返回正确的 URL。

What could be wrong?有什么问题?

Try this:尝试这个:

get_the_permalink()

https://developer.wordpress.org/reference/functions/get_the_permalink/ https://developer.wordpress.org/reference/functions/get_the_permalink/

And I don't think you have to urlencode() it.而且我认为您不必对其进行urlencode()

Edit : It works only in the loop without any parameters.编辑:它只在没有任何参数的循环中工作。 Outside the loop you have to pass the Post ID to the function.在循环之外,您必须将 Post ID 传递给 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM