douliang4858 2014-05-22 14:55
浏览 49

自定义短代码无效

I tried to make my own shortcode for a first time. I have done all things and there is no syntax error. Can somebody tell me what's the mistake? It's not working.

I have implemented this code into function.php file and Dreamweaver tells me that there is no syntax error.

function booknovelist_button( $atts ) {
    // Attributes   
    extract( shortcode_atts( array( 
        'style' => 'rfc',
        'link' => 'www.booknovelist.com'
    ), $atts ) );

    $style  = '$atts[style]'; $choice = ' '; $choicehover = ' ';

    if ($style == 'rfc') {
        $choice='link to image';
        $choicehover='link to image';
    }; 

    if ($style == 'sn') {
        $choice='link to image';
        $choicehover='link to image';
    }

    if ($style == 'pon') {
        $choice='link to image';
        $choicehover='link to image';
    }

    if ($style == 'amazon') {
        $choice='link to image';
        $choicehover='link to image'; 
    }

    echo '<div><a href="',$link,'"><img src="',$choice,'" onmouseover="this.src="',$choicehover,'"" onmouseout="this.src="',$choice,'""></a></div> ' ; } 
}

add_shortcode ( 'bn_btn', 'booknovelist_button' );
  • 写回答

1条回答 默认 最新

  • dongtuo4132 2014-05-22 15:09
    关注

    You should review the documentation for add_shortcode() and look at the examples. You are supposed to return the content that is to be output by the shortcode.

    function footag_func( $atts ) {
        return "foo = {$atts['foo']}";
    }
    add_shortcode('footag', 'footag_func');
    

    So instead of echoing your div, you should return it.

    Your code seems to have other syntax errors as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么