admin管理员组文章数量:1391991
I'm trying to write a shortcode in function.php with a link to share the current page in Twitter. However this link contains some PHP in the href and I can't figure it out how to make it work. Here is the code:
add_shortcode ( "indice", "indice_output" );
function indice_output( $atts, $content="null" ) {
extract( shortcode_atts( array(
'' => ''
), $atts ));
return '<div class="boxed max-width"><div class="indice-title"><span>' . $content . '</span><i class="fa fa-twitter" aria-hidden="true"></i></div></div>';
}
Thanks in advance for the help.
I'm trying to write a shortcode in function.php with a link to share the current page in Twitter. However this link contains some PHP in the href and I can't figure it out how to make it work. Here is the code:
add_shortcode ( "indice", "indice_output" );
function indice_output( $atts, $content="null" ) {
extract( shortcode_atts( array(
'' => ''
), $atts ));
return '<div class="boxed max-width"><div class="indice-title"><span>' . $content . '</span><i class="fa fa-twitter" aria-hidden="true"></i></div></div>';
}
Thanks in advance for the help.
Share Improve this question edited Jul 19, 2017 at 19:07 Digvijayad 2911 silver badge7 bronze badges asked Jul 19, 2017 at 16:19 Mathieu PréaudMathieu Préaud 2035 silver badges18 bronze badges 3 |1 Answer
Reset to default 2You can use ob_start and ob_get_clean to print out your shortcode.
function shortcode_html()
ob_start(); ?>
<div class="boxed max-width">
<div class="indice-title">
<span><?php echo $content; ?></span>
<i class="fa fa-twitter" aria-hidden="true"></i>
</div>
</div> <?php
return ob_get_clean();
}
add_shortcode( 'print_shortcode', 'shortcode_html' );
本文标签: Shortcode return function with link href inside PHP
版权声明:本文标题:Shortcode return function with link href inside PHP 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744653544a2617829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
eval('Delete the entire WordPress installation');
into a link? Your website might have the potential to be hacked in 2 seconds. – Johansson Commented Jul 21, 2017 at 9:38