我需要在WordPress中的短代码中添加一个短代码。
[mycred_link href="http://www.mycred.me"]View portfolio[/mycred_link]上面的这个短代码是来自myCred插件的一个短代码,当用户点击短代码中的链接时,它会给出点。
我需要的是:
若要显示Facebook共享链接,请在短代码中使用。我已经有了一个生成Facebook共享链接的短代码。
我需要这样的东西:
[mycred_link href="[facebook_share_link]"]View portfolio[/mycred_link]当用户在Facebook上分享我的帖子时给他们分。我试过了但没成功。
我还尝试了下面的代码,它给用户指点并打开facebook。但是facebook说URL是无效的。
<?php echo do_shortcode( "[mycred_link href='http://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode(get_permalink()); ?>']View portfolio[/mycred_link]"); ?> 如果我在href之后放双引号,wordpress页脚将完全消失,我的footer.php上正在运行第二段代码
发布于 2020-08-14 14:42:20
问题在myCred插件的代码中。正如您从插件wp-content/plugins/mycred/includes/shortcodes/mycred_link.php的源代码中看到的,您在href属性中传递的内容不会被do_shortcode解析,因此您将无法插入。
正如您从这个答案中看到的:Shortcodes inside a shortcode - wordpress wordpress短代码不会自动堆叠。
幸运的是,该函数的结尾是:
return apply_filters( 'mycred_link', '<a ' . implode( ' ', $attr ) . '>' . do_shortcode( $link_title ) . '</a>', $atts, $link_title );因此,w/o接触插件源代码,您可以使用过滤器,然后做一些与href。我猜是这样的(没有测试)
在主题文件夹中的function.php中插入如下内容:
add_filter('mycred_link','edit_mycred_link',10,3 );
function edit_mycred_link($link_html, $atts, $link_title){
return str_replace('__edit_mycred_link__',do_shortcode('[facebook_share_link]'),$link_html);
}然后在模板文件/ post内容中
[mycred_link href="__edit_mycred_link__"]View portfolio[/mycred_link]那应该能行
发布于 2020-08-19 01:48:50
我终于解决了这个问题。我在wordpress论坛上问了这个问题,一个主持人给了我这个问题。
<?php
echo do_shortcode( '[mycred_link href="http://www.facebook.com/sharer/sharer.php?u=' . urlencode( get_permalink()) . '"]View portfolio[/mycred_link]');
?>https://stackoverflow.com/questions/63413895
复制相似问题