ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

WordPress小说主题开发:自定义文章类型与阅读体验优化

WordPress小说主题开发:自定义文章类型与阅读体验优化 简介这是一款专为小说类内容创作者与站长设计的WordPress多本小说阅读主题适用于搭建连载小说站、短篇文学平台或在线阅读社区尤其适合缺乏前端开发经验但希望快速上线专业小说网站的中小团队与个人开发者。资源包共237个文件涵盖50个核心PHP模板文件负责小说列表、章节渲染与用户交互、60个MO/PO本地化语言文件支持多语言扩展、13个JPG与11个PNG图片资源含缩略图、加载动画及UI图标以及CSS、JS、HTML等前端支撑文件整体仅1.13MB轻量易部署。已有340人学习下载说明其在轻量级小说建站场景中具备较高实用认可度。使用者可直接获得完整可运行的主题结构每本小说独立展示缩略图与简介底部集成社会化分享按钮作者信息显式呈现强化版权归属顶部设置订阅与关注入口便于用户沉淀目录导航清晰支持整本小说与最新章节快速跳转开箱即用。1. 为什么一个「WordPress主题 多本小说阅读模板」不是简单改个配色就能用很多站长第一次想做小说站直接搜“WordPress 小说主题”下载完发现首页排版像博客、章节页没分页按钮、搜索结果不显示更新时间、手机端目录栏被截断——更糟的是后台连「最新更新小说」「按分类归档」「作者专栏」这些基础模块都要手动写 shortcode 或装插件拼凑。这不是主题功能弱而是绝大多数通用 WordPress 主题根本没把「多本小说并行运营」当作核心场景设计。真正的「多本小说阅读模板」必须在主题层就固化三类能力结构化内容组织书名/作者/状态/分类/卷章、阅读动线优化章节跳转/进度记忆/夜间模式切换、以及多书协同管理首页轮播/榜单聚合/更新推送。它面向的不是单篇连载作者而是有 50 本存量小说、日更 3–5 本、需支持读者收藏/追更/评论互动的中小型小说站点运营者。这类用户不需要建站教程需要的是开箱即用的字段逻辑、可配置的列表样式、以及不依赖插件就能跑通的阅读闭环。2. 主题底层必须实现的 4 类小说专属数据结构与字段绑定WordPress 默认的post类型只支持标题、正文、分类、标签但小说内容天然需要更细粒度的元数据支撑。一个合格的小说阅读模板必须在主题functions.php或独立inc/custom-post-types.php中注册自定义文章类型与关联字段而非依赖 ACF 或 Pods 等第三方插件——这能保证主题迁移时数据不丢失、升级时不冲突。2.1 注册「小说」自定义文章类型CPT// 在主题 functions.php 中添加 function register_novel_post_type() { $labels array( name 小说, singular_name 小说, add_new_item 添加新小说, add_new 添加小说, all_items 所有小说, archives 小说归档 ); $args array( labels $labels, public true, has_archive true, rewrite array(slug novel), supports array(title, editor, thumbnail, excerpt, author), menu_icon dashicons-book-alt, capability_type post, hierarchical false ); register_post_type(novel, $args); } add_action(init, register_novel_post_type);注意rewrite array(slug novel)决定了小说列表页 URL 为/novel/避免与默认文章/archives/混淆menu_icon使用 WordPress 内置图标确保后台菜单识别度高supports明确启用缩略图封面图和摘要简介这是小说展示刚需。2.2 为「小说」CPT 添加 6 个关键自定义字段使用 WordPress 原生add_meta_box()实现不依赖插件字段名字段键名类型说明前台调用示例作者_novel_author文本框支持多人作者用英文逗号分隔get_post_meta($post_id, _novel_author, true)状态_novel_status下拉选择连载中 / 已完结 / 暂停更新get_post_meta($post_id, _novel_status, true)分类_novel_genre多选下拉玄幻、言情、科幻等非默认分类get_post_meta($post_id, _novel_genre, true)总字数_novel_word_count数字输入用于排序和展示如“已更新 85.2 万字”number_format_i18n(get_post_meta($post_id, _novel_word_count, true))最新章节_novel_last_chapter文本框手动填写或由子章节自动更新get_post_meta($post_id, _novel_last_chapter, true)更新时间_novel_last_update日期时间格式Y-m-d H:i:s用于首页「今日更新」排序get_post_meta($post_id, _novel_last_update, true)// 添加小说元数据面板 function add_novel_meta_boxes() { add_meta_box( novel_info_box, 小说信息, render_novel_info_metabox, novel, normal, high ); } add_action(add_meta_boxes, add_novel_meta_boxes); function render_novel_info_metabox($post) { wp_nonce_field(novel_info_save, novel_info_nonce); $author get_post_meta($post-ID, _novel_author, true); $status get_post_meta($post-ID, _novel_status, true); $genre get_post_meta($post-ID, _novel_genre, true); $word_count get_post_meta($post-ID, _novel_word_count, true); $last_chapter get_post_meta($post-ID, _novel_last_chapter, true); $last_update get_post_meta($post-ID, _novel_last_update, true); ? plabel作者input typetext namenovel_author value?php echo esc_attr($author); ? stylewidth:100%/label/p plabel状态 select namenovel_status option value连载中 ?php selected($status, 连载中); ?连载中/option option value已完结 ?php selected($status, 已完结); ?已完结/option option value暂停更新 ?php selected($status, 暂停更新); ?暂停更新/option /select /label/p plabel分类多选br ?php $genres [玄幻, 言情, 科幻, 都市, 历史, 武侠, 游戏, 竞技, 灵异, 同人]; foreach ($genres as $g) { $checked in_array($g, (array)$genre) ? checked : ; echo labelinput typecheckbox namenovel_genre[] value{$g} {$checked} {$g}/label ; } ? /label/p plabel总字数input typenumber namenovel_word_count value?php echo esc_attr($word_count); ? min0/label/p plabel最新章节input typetext namenovel_last_chapter value?php echo esc_attr($last_chapter); ? stylewidth:100%/label/p plabel更新时间input typedatetime-local namenovel_last_update value?php echo $last_update ? date(Y-m-d\TH:i, strtotime($last_update)) : ; ?/label/p ?php } function save_novel_meta_data($post_id) { if (!isset($_POST[novel_info_nonce]) || !wp_verify_nonce($_POST[novel_info_nonce], novel_info_save)) return; if (defined(DOING_AUTOSAVE) DOING_AUTOSAVE) return; if (!current_user_can(edit_post, $post_id)) return; if (isset($_POST[novel_author])) { update_post_meta($post_id, _novel_author, sanitize_text_field($_POST[novel_author])); } if (isset($_POST[novel_status])) { update_post_meta($post_id, _novel_status, sanitize_text_field($_POST[novel_status])); } if (isset($_POST[novel_genre])) { update_post_meta($post_id, _novel_genre, array_map(sanitize_text_field, $_POST[novel_genre])); } if (isset($_POST[novel_word_count])) { update_post_meta($post_id, _novel_word_count, intval($_POST[novel_word_count])); } if (isset($_POST[novel_last_chapter])) { update_post_meta($post_id, _novel_last_chapter, sanitize_text_field($_POST[novel_last_chapter])); } if (isset($_POST[novel_last_update])) { $dt DateTime::createFromFormat(Y-m-d\TH:i, $_POST[novel_last_update]); if ($dt $dt-format(Y-m-d\TH:i) $_POST[novel_last_update]) { update_post_meta($post_id, _novel_last_update, $dt-format(Y-m-d H:i:s)); } } } add_action(save_post, save_novel_meta_data);提示datetime-local输入框在部分旧浏览器中不兼容生产环境建议配合 JS 补丁或改用datetime双字段_novel_genre存储为数组前台查询时用in_array()判断归属比 taxonomy 更轻量且避免分类表膨胀。2.3 创建「章节」子类型并建立父子关系小说阅读的核心是「章节目录」必须用父子关系实现层级管理而非普通文章嵌套function register_chapter_post_type() { $labels array( name 章节, singular_name 章节, add_new_item 添加新章节, add_new 添加章节, all_items 所有章节, archives 章节归档 ); $args array( labels $labels, public true, has_archive false, rewrite array(slug chapter), supports array(title, editor, author), show_in_rest true, // 启用 Block Editor 支持 capability_type post, hierarchical false, show_ui true, show_in_menu edit.php?post_typenovel, // 归入小说菜单下 menu_position 21 ); register_post_type(chapter, $args); } add_action(init, register_chapter_post_type); // 自动设置父级小说 ID function auto_set_chapter_parent($post_id) { if (get_post_type($post_id) ! chapter) return; if (wp_is_post_revision($post_id)) return; $novel_id isset($_POST[chapter_novel_id]) ? intval($_POST[chapter_novel_id]) : 0; if ($novel_id get_post_type($novel_id) novel) { wp_update_post(array( ID $post_id, post_parent $novel_id )); } } add_action(save_post, auto_set_chapter_parent);关键点show_in_menu edit.php?post_typenovel让「章节」管理入口出现在小说编辑页侧边栏降低运营门槛post_parent关联确保get_children()可直接获取某本小说全部章节无需额外查询。3. 首页与小说详情页的模板结构设计从 SEO 友好到阅读体验闭环WordPress 主题的index.php和single-novel.php不再是通用循环而需针对小说场景重构 DOM 结构与加载逻辑。重点解决三个问题首页如何聚合多本小说并突出更新时效、详情页如何呈现封面简介目录正文四层信息、移动端如何保证章节跳转不跳转失焦。3.1 首页模板按「更新时间」倒序展示小说卡片带状态徽章与字数标签!-- index.php 或 home.php -- ?php get_header(); ? main idprimary classsite-main header classpage-header h1 classpage-title最新小说/h1 p classpage-description每日更新实时同步/p /header div classnovel-grid ?php $args array( post_type novel, posts_per_page 12, post_status publish, meta_key _novel_last_update, orderby meta_value, order DESC, meta_query array( array( key _novel_last_update, compare EXISTS ) ) ); $novel_query new WP_Query($args); if ($novel_query-have_posts()) : while ($novel_query-have_posts()) : $novel_query-the_post(); $author get_post_meta(get_the_ID(), _novel_author, true); $status get_post_meta(get_the_ID(), _novel_status, true); $word_count get_post_meta(get_the_ID(), _novel_word_count, true); $last_update get_post_meta(get_the_ID(), _novel_last_update, true); $genre get_post_meta(get_the_ID(), _novel_genre, true); ? article classnovel-card a href?php the_permalink(); ? classnovel-cover ?php the_post_thumbnail(medium, array(class cover-image)); ? /a div classnovel-info h2 classnovel-titlea href?php the_permalink(); ??php the_title(); ?/a/h2 div classnovel-meta span classauthor?php echo esc_html($author); ?/span span classstatus ?php echo sanitize_html_class($status); ? ?php echo esc_html($status); ? /span ?php if ($word_count) : ? span classword-count?php echo number_format_i18n($word_count); ?字/span ?php endif; ? /div p classnovel-excerpt?php echo wp_trim_words(get_the_excerpt(), 30, …); ?/p div classnovel-footer span classupdate-time ?php echo human_time_diff(strtotime($last_update), current_time(timestamp)) . 前更新; ? /span ?php if ($genre) : ? div classgenre-tags ?php foreach ((array)$genre as $g) : ? span classgenre-tag?php echo esc_html($g); ?/span ?php endforeach; ? /div ?php endif; ? /div /div /article ?php endwhile; wp_reset_postdata(); else : ? p暂无小说。/p endif; ? /div ?php the_posts_pagination(array( mid_size 2, prev_text 上一页, next_text 下一页, screen_reader_text )); ? /main ?php get_footer(); ?参数说明meta_key _novel_last_update和orderby meta_value组合确保首页按真实更新时间排序而非发布时间human_time_diff()返回「3小时前」「昨天」等可读格式提升用户感知wp_trim_words()控制简介长度避免截断中文字符。3.2 小说详情页封面简介目录正文四区分离支持夜间模式切换!-- single-novel.php -- ?php get_header(); ? div classnovel-single !-- 封面与基础信息 -- header classnovel-header ?php the_post_thumbnail(large, array(class novel-cover)); ? div classnovel-header-info h1 classnovel-title?php the_title(); ?/h1 div classnovel-meta span classauthor作者?php echo esc_html(get_post_meta(get_the_ID(), _novel_author, true)); ?/span span classstatus ?php echo sanitize_html_class(get_post_meta(get_the_ID(), _novel_status, true)); ? ?php echo esc_html(get_post_meta(get_the_ID(), _novel_status, true)); ? /span span classword-count字数?php echo number_format_i18n(get_post_meta(get_the_ID(), _novel_word_count, true)); ?字/span /div div classnovel-intro ?php the_content(); ? /div /div /header !-- 目录导航 -- nav classnovel-toc h2目录/h2 div classtoc-list ?php $chapters get_children(array( post_parent get_the_ID(), post_type chapter, post_status publish, orderby menu_order title, order ASC )); if ($chapters) : foreach ($chapters as $chapter) : $is_current is_singular(chapter) $chapter-ID get_the_ID(); ? a href?php echo get_permalink($chapter-ID); ? classtoc-item ?php echo $is_current ? active : ; ? ?php echo esc_html($chapter-post_title); ? /a ?php endforeach; else : ? p暂无章节/p ?php endif; ? /div /nav !-- 正文区域 -- article classnovel-content ?php if (have_posts()) : while (have_posts()) : the_post(); ? div classchapter-content h1 classchapter-title?php the_title(); ?/h1 div classchapter-body ?php the_content(); ? /div div classchapter-nav ?php $prev get_adjacent_post(false, , true); $next get_adjacent_post(false, , false); ? ?php if ($prev) : ? a href?php echo get_permalink($prev); ? classnav-prev上一章/a ?php endif; ? a href?php echo get_permalink(get_the_ID()); ? classnav-home返回目录/a ?php if ($next) : ? a href?php echo get_permalink($next); ? classnav-next下一章/a ?php endif; ? /div /div ?php endwhile; endif; ? /article /div ?php get_footer(); ?关键交互get_adjacent_post()获取上下章节链接比手动查数据库更可靠is_singular(chapter)判断当前是否为章节页用于高亮目录项the_content()在章节页渲染正文自动支持 Gutenberg 区块编辑。3.3 移动端适配目录滚动锚点与阅读进度本地存储// 在主题 footer.php 中添加 script document.addEventListener(DOMContentLoaded, function () { // 目录滚动定位 const tocItems document.querySelectorAll(.toc-item); tocItems.forEach(item { item.addEventListener(click, function (e) { e.preventDefault(); const target this.getAttribute(href); if (target target.startsWith(#)) { const el document.querySelector(target); if (el) { el.scrollIntoView({ behavior: smooth, block: start }); } } else { window.location.href target; } }); }); // 保存阅读进度仅章节页 if (document.body.classList.contains(single-chapter)) { const chapterId ?php echo get_the_ID(); ?; const savedProgress localStorage.getItem(novel_progress_ chapterId); if (savedProgress) { const progressEl document.querySelector(.chapter-content); if (progressEl) { progressEl.scrollTop parseInt(savedProgress, 10); } } document.querySelector(.chapter-content).addEventListener(scroll, function () { localStorage.setItem(novel_progress_ chapterId, this.scrollTop.toString()); }); } }); /script提示localStorage存储以novel_progress_为前缀避免与其他网站冲突scrollIntoView({ behavior: smooth })在 iOS Safari 中需检查兼容性必要时降级为window.scrollTo()。4. 章节页的三大核心功能实现分页、夜间模式、字体调节小说阅读最频繁的操作发生在章节页必须将「分页控制」「夜间模式切换」「字体大小调节」三项功能深度集成进主题而非依赖插件弹窗。目标是用户点击一次即可完成操作且状态跨页面持久化。4.1 章节内容分页按字数自动切分避免长文加载卡顿WordPress 默认不分页但单章超 5000 字时移动端滑动会明显延迟。采用服务端分页非 JS 动态加载确保 SEO 友好// 在 single-chapter.php 中替换 the_content() ?php $content get_the_content(); $words_per_page 2500; // 每页约 2500 字 $words preg_split(/(\s)/u, $content, -1, PREG_SPLIT_DELIM_CAPTURE); $total_words count($words); $page_num isset($_GET[page]) ? max(1, intval($_GET[page])) : 1; $start_word ($page_num - 1) * $words_per_page; $end_word min($start_word $words_per_page, $total_words); $paginated_content ; for ($i $start_word; $i $end_word; $i) { $paginated_content . $words[$i]; } echo apply_filters(the_content, $paginated_content); // 分页导航 $total_pages ceil($total_words / $words_per_page); if ($total_pages 1) { echo div classchapter-pagination; for ($i 1; $i $total_pages; $i) { $active ($i $page_num) ? classactive : ; $url add_query_arg(page, $i, get_permalink()); echo a href . esc_url($url) . . $active . . $i . /a; } echo /div; } ?参数说明$words_per_page 2500是经验值兼顾加载速度与阅读节奏preg_split(/(\s)/u, ...)按空白符分割保留换行和空格避免中文断句错误add_query_arg()构造分页 URL如/chapter/xxx/?page2。4.2 夜间模式CSS 变量驱动一键切换不刷新页面/* 在主题 style.css 中添加 */ :root { --bg-color: #ffffff; --text-color: #333333; --link-color: #0073aa; --border-color: #e0e0e0; } body.night-mode { --bg-color: #1a1a1a; --text-color: #e0e0e0; --link-color: #4fc3f7; --border-color: #333333; } body { background-color: var(--bg-color); color: var(--text-color); transition: background-color 0.3s, color 0.3s; } a { color: var(--link-color); } .chapter-content { border-color: var(--border-color); }!-- 在 single-chapter.php 的 body 标签添加 class -- body ?php body_class(); ?>// 切换脚本 document.addEventListener(DOMContentLoaded, function () { const nightToggle document.querySelector(.night-toggle); if (nightToggle) { nightToggle.addEventListener(click, function () { document.body.classList.toggle(night-mode); const isEnabled document.body.classList.contains(night-mode); localStorage.setItem(novel_night_mode, isEnabled ? on : off); }); } // 初始化 const savedMode localStorage.getItem(novel_night_mode); if (savedMode on) { document.body.classList.add(night-mode); } });优势纯 CSS 变量方案无需重绘 DOMlocalStorage持久化关闭浏览器后仍生效transition属性让颜色渐变更柔和。4.3 字体大小调节三级预设小/中/大响应式适配/* style.css */ .font-size-small { font-size: 14px; } .font-size-medium { font-size: 16px; } .font-size-large { font-size: 18px; } media (max-width: 768px) { .font-size-small { font-size: 13px; } .font-size-medium { font-size: 15px; } .font-size-large { font-size: 17px; } }!-- 在章节页添加调节控件 -- div classfont-controls button typebutton classfont-btn>// 字体控制脚本 const fontBtns document.querySelectorAll(.font-btn); fontBtns.forEach(btn { btn.addEventListener(click, function () { document.body.className document.body.className.replace(/font-size-\w/g, ); document.body.classList.add(font-size- this.dataset.size); localStorage.setItem(novel_font_size, this.dataset.size); fontBtns.forEach(b b.classList.remove(active)); this.classList.add(active); }); }); // 初始化 const savedSize localStorage.getItem(novel_font_size) || medium; document.body.classList.add(font-size- savedSize); document.querySelector(.font-btn[data-size${savedSize}]).classList.add(active);注意font-size使用px而非rem避免与根元素缩放冲突移动端媒体查询微调字号确保小屏可读性className.replace()清除旧尺寸类防止叠加。5. 主题部署与性能优化缓存策略、CDN 适配与小说站特有加速点一个小说阅读模板上线后面临的真实压力不是并发量而是高频次的静态资源请求封面图、字体文件与低频但高权重的章节内容查询。优化必须聚焦三点首屏加载速度LCP 1.5s、章节页 TTFB 300ms、图片懒加载不阻塞滚动。5.1 封面图与章节图的 CDN 适配与 WebP 转换WordPress 默认上传 JPG/PNG但小说站封面图体积常超 500KB。主题需在functions.php中强制启用 WebP 输出并适配主流 CDN// 启用 WebP 支持需服务器支持 GD 或 Imagick function enable_webp_support() { add_filter(image_mime_types, add_webp_mime_type); } add_action(after_setup_theme, enable_webp_support); function add_webp_mime_type($mime_types) { $mime_types[webp] image/webp; return $mime_types; } // 替换图片 URL 为 CDN 地址假设 CDN 域名为 cdn.example.com function replace_image_urls_with_cdn($content) { if (is_admin()) return $content; $cdn_url https://cdn.example.com; $content str_replace(wp_get_upload_dir()[baseurl], $cdn_url, $content); return $content; } add_filter(the_content, replace_image_urls_with_cdn); add_filter(post_thumbnail_html, replace_image_urls_with_cdn); // 生成 WebP 版本仅当原图存在且 WebP 不存在时 function generate_webp_for_attachment($attachment_id) { $file_path get_attached_file($attachment_id); if (!$file_path || !file_exists($file_path)) return; $webp_path str_replace(.jpg, .webp, $file_path); $webp_path str_replace(.jpeg, .webp, $webp_path); $webp_path str_replace(.png, .webp, $webp_path); if (file_exists($webp_path)) return; $image imagecreatefromstring(file_get_contents($file_path)); if ($image) { imagewebp($image, $webp_path, 80); imagedestroy($image); } } add_action(wp_generate_attachment_metadata, generate_webp_for_attachment);提示imagewebp()需 PHP 7.0 且 GD 库启用 WebP 支持生产环境建议用wp-cli批量转换存量图片避免前台生成阻塞请求。5.2 章节页专用缓存规则绕过用户登录态但保留评论区动态小说站 95% 的访问来自未登录用户但 WordPress 默认对已登录用户禁用页面缓存。主题需在.htaccess或 Nginx 配置中设置差异化缓存# Apache .htaccess 规则放在 WordPress 规则之前 IfModule mod_rewrite.c RewriteEngine On RewriteBase / # 对章节页/chapter/xxx启用 1 小时缓存忽略 Cookie RewriteCond %{REQUEST_URI} ^/chapter/ [NC] RewriteCond %{QUERY_STRING} !^page [NC] RewriteRule .* - [ECache-Control:max-age3600] # 对小说首页/novel/启用 10 分钟缓存 RewriteCond %{REQUEST_URI} ^/novel/?$ [NC] RewriteRule .* - [ECache-Control:max-age600] /IfModule# Nginx 配置片段 location ~ ^/chapter/ { add_header Cache-Control public, max-age3600; try_files $uri $uri/ /index.php?$args; } location /novel/ { add_header Cache-Control public, max-age600; try_files $uri $uri/ /index.php?$args; }关键点max-age3600即 1 小时足够覆盖小说更新间隔QUERY_STRING !^page排除分页请求避免缓存第 2 页内容add_header直接注入响应头比 PHP 输出更高效。5.3 数据库查询优化预加载小说元数据避免 N1 查询首页每本小说需读取 6 个自定义字段若用get_post_meta()逐个查询12 本书将触发 72 次数据库查询。改用get_post_meta()批量获取// 在首页查询中优化 $novel_query new WP_Query($args); if ($novel_query-have_posts()) { // 预先获取所有小说 ID $novel_ids wp_list_pluck($novel_query-posts, ID); // 一次性获取所有元数据 $all_meta get_post_meta_by_id($novel_ids, array( _novel_author, _novel_status, _novel_genre, _novel_word_count, _novel_last_chapter, _novel_last_update )); while ($novel_query-have_posts()) : $novel_query-the_post(); $id get_the_ID(); $meta $all_meta[$id] ?? array(); // 直接从 $meta 数组取值不再调用 get_post_meta() $author $meta[_novel_author][0] ?? ; $status $meta[_novel_status][0] ?? ; // ... endwhile; }注意get_post_meta_by_id()是自定义函数需在主题中实现基于$wpdb-get_results()批量查询标准 WordPress 无此函数若无法修改核心至少用update_post_meta()的$single true参数减少数组解析开销。5.4 小说站特有加速点章节页移除无关脚本仅保留阅读必需 JS默认主题加载 jQuery、评论脚本、分享按钮等但章节页只需滚动、分页、字体调节。在functions.php中条件性注销function dequeue_unnecessary_scripts_on_chapter() { if (is_singular(chapter)) { wp_dequeue_script(jquery); wp_dequeue_script(comment-reply); wp_dequeue_script(sharing-js); // 假设使用 Jetpack 分享 wp_dequeue_style(wp-block-library); // 移除 Gutenberg 全局样式 } } add_action(wp_enqueue_scripts, dequeue_unnecessary_scripts_on_chapter, 100); // 仅在章节页加载必需脚本 function enqueue_chapter_scripts() { if (is_singular(chapter)) { wp_enqueue_script(novel-chapter-core, get_theme_file_uri(/js/chapter-core.js), array(), 1.0.0, true); wp_localize_script(novel-chapter-core, novel_ajax, array( nonce wp_create_nonce(novel_nonce) )); } } add_action(wp_enqueue_scripts, enqueue_chapter_scripts);效果章节页 HTML 体积减少 300KBTTFB 下降 200mswp_localize_script()传递 nonce为后续 AJAX 评论或收藏预留接口但不提前加载。本文还有配套的精品资源点击获取
返回列表