Php WordPress-调用函数-使用自定义标记时不工作
下面的函数通过将其添加到>The_content()来工作,但是,我想通过自定义标记将其显示在html标记中的自定义位置,当我尝试此操作时,我遇到了一个PHP错误,我确信这是一个非常简单的问题,但我始终看不到这个问题Php WordPress-调用函数-使用自定义标记时不工作,php,wordpress,function,filter,tags,Php,Wordpress,Function,Filter,Tags,下面的函数通过将其添加到>The_content()来工作,但是,我想通过自定义标记将其显示在html标记中的自定义位置,当我尝试此操作时,我遇到了一个PHP错误,我确信这是一个非常简单的问题,但我始终看不到这个问题 // code from crunchify function supersun_social_sharing_buttons($content) { global $post; if(is_singular() || is_home()){
// code from crunchify
function supersun_social_sharing_buttons($content) {
global $post;
if(is_singular() || is_home()){
// Get current page URL
$supersunURL = urlencode(get_permalink());
// Get current page title
$supersunTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$supersunThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$supersunTitle.'&url='.$supersunURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$supersunURL;
$googleURL = 'https://plus.google.com/share?url='.$supersunURL;
$whatsappURL = 'whatsapp://send?text='.$supersunTitle . ' ' . $supersunURL;
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$supersunURL.'&media='.$supersunThumbnail[0].'&description='.$supersunTitle;
// Add sharing button at the end of page/page content
$variable .= '<div class="supersun-social">';
$variable .= '<a class="supersun-social-link supersun-twitter" href="'. $twitterURL .'" target="_blank" title="Share on Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-facebook" href="'.$facebookURL.'" target="_blank" title="Share on Facebook"><i class="fa fa-facebook" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-whatsapp" href="'.$whatsappURL.'" target="_blank" title="Share on Whatsapp"><i class="fa fa-whatsapp" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-googleplus" href="'.$googleURL.'" target="_blank" title="Share on Google+"><i class="fa fa-google-plus" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-pinterest" href="'.$pinterestURL.'" target="_blank" title="Share on Pinterest"><i class="fa fa-pinterest" aria-hidden="true"></i></a>';
$variable .= '</div>';
return $variable.$content;
}else{
// if not a post/page then don't include sharing button
return $variable.$content;
}
};
add_filter( 'the_content', 'supersun_social_sharing_buttons');
//crunchify的代码
功能超级运行社交共享按钮($content){
全球$员额;
if(is_singular()| | is_home()){
//获取当前页面URL
$supersunURL=urlencode(get_permalink());
//获取当前页面标题
$superstatle=str_replace('',%20',获取标题());
//获取pinterest的帖子缩略图
$supersunThumbnail=wp\u get\u attachment\u image\u src(get\u post\u thumbnail\u id($post->id),'full');
//不使用任何脚本构建共享URL
$twitterURL=https://twitter.com/intent/tweet?text=“.$supersunTitle.&;url=”.$supersunURL.&;via=Crunchify”;
$facebookURL=https://www.facebook.com/sharer/sharer.php?u=“.$supersunURL;
$googleURL=https://plus.google.com/share?url=“.$supersunURL;
$whatsappURL=whatsapp://send?text=“.$supersunTitle.”.$supersunURL;
$pinterestURLhttps://pinterest.com/pin/create/button/?url=“.$supersunURL.&;media=”.$supersunThumbnail[0]。&;description=”.$supersunTitle;
//在页面/页面内容末尾添加共享按钮
$variable.='';
$variable.='';
$variable.='';
$variable.='';
$variable.='';
$variable.='';
$variable.='';
返回$variable.$content;
}否则{
//如果不是帖子/页面,则不包括共享按钮
返回$variable.$content;
}
};
添加过滤器(“内容”、“超级社交共享”按钮);
添加时会显示此错误消息
符合我的主题
非常感谢您抽出时间。很抱歉,该网站目前还没有上线,我认为这应该是一个有经验的眼睛容易修复的人
通过
在…上
在里面
直接调用函数时需要传递参数,而不是在add\u filter
中。像这样
你能读懂你得到的错误吗?上面说什么?“失踪…”是的,请原谅我缺乏经验,我不完全确定这是什么意思?如果您能提供任何帮助,我们将不胜感激。我明白了,但在这种情况下,参数是什么?抱歉,如果我给人的印象是愚蠢的,我仍然在学习-我尝试了$content,但这不起作用。您的函数获取参数,转换(或不转换)并返回。当您从add\u filter
调用该参数时,该参数是post的内容。当您直接调用它时,您必须自己传递一些参数。例如:
啊,好的,但是参数必须是特定的吗?我的意思是,在我的大脑中,我想称之为$content,因为这是我函数的内容,我会用什么来替换“一些数据”,以便让我的函数内容显示出来?我不明白你想要实现什么。如果您的代码有效,请调用add_filter('the_content'、'supersun_social_sharing_button')
足以将其应用于主题。没必要再打电话了。如果您没有看到内容更改,请在函数中查找trubles)我想在标记中的一个位置显示它,而不是“内容”-我希望创建一个自定义标记,并在需要它的时间和位置插入它。。。这是可以实现的吗?