wordpress - 激活插件时创建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');
但是由此生成的页面有样式问题。它不是全宽的。
解决方案
public function quote_shortcode() {
if ( ! is_admin() ) {
ob_start();
include(__DIR__.'/../template/create-quote.php');
return ob_get_clean();
}
}
这出于某种原因 - 在创建短代码时添加了此代码。
推荐阅读
- numpy - input reshape problem about using tf.layers.conv3d
- reactjs - 在画布上进行文本处理后提取图像数据url,并在Material-UI的CardMedia中显示结果
- vuejs2 - 事件和自引用组件 vue.js
- c - 在不运行合成器的情况下使用 x11 协议获取覆盖窗口需要什么?
- google-apps-script - 编写用于删除工作表数据创建的日历项目的代码
- vba - 根据 Access 中的多个条件返回子表单值
- php - 从 foreach 循环中获取唯一值时面临问题
- tensorflow - 如何在张量流中打印出预测值
- java - 谁可以进行此 JPQL 查询?
- android - 系统应用程序在供应商分区中读取/写入数据