Wordpress问题创建短代码

时间:2017-01-03 01:08:27

标签: php wordpress

我是初学者,正在开发他学习如何在WordPress上创建我的第一个短代码,以便向页面或帖子添加短代码[contact_form]的用户将在他们主题的任何页面上看到它。

这里留言 Parse error: syntax error, unexpected 'add_shortcode' (T_STRING), expecting function (T_FUNCTION) in /Users/brandonpowell/sites/valet/wordpress-development/web/app/themes/sage-8.5.0/lib/shortcode.php on line 16

<?php

class Settings {
      // Conact Form shortcode
      public function allb_contact_form( $atts, $content = null  ) {
        //[contact_form]
        //get the attribute_escape
        $atts = shortcode_atts(
            array(),
            $atts,
            'contact_form'
          );
          //return HTML
          include 'lib/inc/thmeplates/contact-form.php';

    add_shortcode( 'contact_form', 'allb_contact_form' ); // Line 16
  }
new Settings();

1 个答案:

答案 0 :(得分:1)

只是你的格式

class Settings {
      // Conact Form shortcode

    public function allb_contact_form( $atts, $content = null  ) {
          //[contact_form]
          //get the attribute_escape
          $atts = shortcode_atts(
            array(),
            $atts,
            'contact_form'
          );
          //return HTML
          include 'lib/inc/thmeplates/contact-form.php';

        add_shortcode( 'contact_form', 'allb_contact_form' ); // Line 16
    }

}// this was missing