Php 如何在wordpress上使用';用';或;
我有一个代码,它用一个外部div(用于在图像上悬停时的共享按钮)包装帖子上的每个图像。 问题是,当我想写_permalink()时;在function.php中,它被包装在a href标记中的“或”中 这导致共享链接如下所示: 这是function.php中的代码:Php 如何在wordpress上使用';用';或;,php,wordpress,Php,Wordpress,我有一个代码,它用一个外部div(用于在图像上悬停时的共享按钮)包装帖子上的每个图像。 问题是,当我想写_permalink()时;在function.php中,它被包装在a href标记中的“或”中 这导致共享链接如下所示: 这是function.php中的代码: function breezer_addDivToImage( $content ) { // A regular expression of what to look for. $pattern = '/(<i
function breezer_addDivToImage( $content ) {
// A regular expression of what to look for.
$pattern = '/(<img([^>]*)>)/i';
// What to replace it with. $1 refers to the content in the first 'capture group', in parentheses above
$the_url = the_permalink();
$replacement = '<div class="imgWrap">
$1
<div class="imgDescription">
<div class="theShareLinks">
<img src="http://localhost/mySite/wp-content/uploads/2014/08/dfc2.png" />
<a href="http://twitter.com/share?text=&url=<?php the_permalink(); ?>" class="img-twitter" title="Share on Twitter"></a>
<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>?" title="Share on Facebook" onclick="window.open(this.href, \'newwin\', \'width=500, height=200\'); return false;" class="img-facebook"></a>
<a href="https://plus.google.com/share?url=<?php the_permalink(); ?>" class="img-google" title="Share on Google"></a>
</div>
</div>
</div>';
// run preg_replace() on the $content
$content = preg_replace( $pattern, $replacement, $content );
// return the processed content
return $content;
}
add_filter( 'the_content', 'breezer_addDivToImage' );
function breezer\u addDivToImage($content){
//查找内容的正则表达式。
$pattern=/(
';
//在$content上运行preg_replace()
$content=preg_replace($pattern,$replacement,$content);
//返回已处理的内容
返回$content;
}
添加_过滤器('the_content'、'breezer_addDivToImage');
以下是“^上方代码中包装在“”中的行:
更改:
<a href="http://twitter.com/share?text=&url=<?php the_permalink(); ?>" class="img-twitter" title="Share on Twitter"></a>
到
应该管用。谢谢@Howlin!很管用:)
<a href="http://twitter.com/share?text=&url=<?php the_permalink(); ?>" class="img-twitter" title="Share on Twitter"></a>
<a href="http://twitter.com/share?text=&url='.get_the_permalink() .'" class="img-twitter" title="Share on Twitter"></a>