【问题标题】:Wordpress Shortcode syntax error, unexpected '}'Wordpress 简码语法错误,意外的“}”
【发布时间】:2014-11-19 12:47:26
【问题描述】:

我正在学习如何制作 wordpress 主题。我做得很好。现在我想制作简码。但是在第 17 行的 E:\xampp\htdocs\wordpress\wp-content\themes\freedom\shortcodes.php 中显示 Parse error: syntax error, unexpected '}' 。我仍然不知道是什么问题。这是代码。

<?php

function slider_function( $atts ) {
    $atts = extract( shortcode_atts( 
                    array( 
                        'tittle'=>'', 
                        'description'=>'',
                        'button'=>'',
                        'button_url'=>''
                    ),$atts ) );
    return '
    <div class="slider">
        <h1>"' . $atts['tittle'] . '"</h1>
        <h2>"' . $atts['tittle'] . '"</h2>
        <a href="' . $atts['tittle'] . '" class="btn-modern text-center"></a>
    </div>'
}

add_shortcode( 'slider','slider_function' );

?>

【问题讨论】:

    标签: wordpress function syntax-error shortcode codex


    【解决方案1】:

    看看这段代码短代码是如何工作的,看看你的代码返回了什么。

    function bartag_func( $atts ) {
        $a = shortcode_atts( array(
            'foo' => 'something',
            'bar' => 'something else',
        ), $atts );
    
        return "foo = {$a['foo']}";
    }
    add_shortcode( 'bartag', 'bartag_func' );
    

    【讨论】:

      【解决方案2】:

      您忘记了分号 /div&gt;'<strong><em>;</em></strong>

      function slider_function( $atts ) {
      $atts = extract( shortcode_atts( 
                      array( 
                          'tittle'=>'', 
                          'description'=>'',
                          'button'=>'',
                          'button_url'=>''
                      ),$atts ) );
      return '
      <div class="slider">
          <h1>"' . $atts['tittle'] . '"</h1>
          <h2>"' . $atts['tittle'] . '"</h2>
          <a href="' . $atts['tittle'] . '" class="btn-modern text-center"></a>
      </div>';
      }
      
      add_shortcode( 'slider','slider_function' );
      

      【讨论】:

      • 我知道这里发生了什么。
      猜你喜欢
      • 2012-06-17
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      相关资源
      最近更新 更多