首页 > 解决方案 > 激活插件时创建wordpress模板

问题描述

激活插件时,我想创建一个带有短代码的新模板。我正在使用插件样板生成器。我尝试使用此https://github.com/tommcfarlin/page-template-example/但它不起作用。我还尝试使用创建页面

function add_my_custom_page() {
    // Create post object
    $my_post = array(
      'post_title'    => wp_strip_all_tags( 'My Custom Page' ),
      'post_content'  => '[shortcode]',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     => 'page',
      'page_template'  => 'templates/template-full-width.php'
    );

    // Insert the post into the database
    wp_insert_post( $my_post );
}

register_activation_hook(__FILE__, 'add_my_custom_page');

但是由此生成的页面有样式问题。它不是全宽的。

标签: wordpress

解决方案


public function quote_shortcode() {
        if ( ! is_admin() ) {
            ob_start();
            include(__DIR__.'/../template/create-quote.php');
            return ob_get_clean();
        }

    }

这出于某种原因 - 在创建短代码时添加了此代码。


推荐阅读