基础配置
WordPress 安装完成后,需要进行一系列基础配置来优化你的站点。本章节详细介绍各项配置项。
⚙️ 常规设置
基本设置页面
路径:后台 → 设置 → 常规
| 设置项 | 说明 | 建议值 |
|---|---|---|
| 网站标题 | 站点名称 | 简洁明了 |
| 副标题 | 站点描述 | 包含关键词 |
| WordPress 地址 (URL) | 程序安装地址 | 不要轻易修改 |
| 网站地址 (URL) | 访问地址 | 建议使用 HTTPS |
| 电子邮件 | 管理员邮箱 | 有效邮箱 |
固定链接设置
路径:后台 → 设置 → 固定链接
推荐配置:
php
// 伪静态规则 - Nginx
location / {
try_files $uri $uri/ /index.php?$args;
}
// 伪静态规则 - Apache (.htaccess)
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
🎨 显示设置
路径:后台 → 设置 → 讨论
评论设置
php
// 在 functions.php 中设置评论
add_filter('pre_comment_approved', function($approved) {
// 垃圾评论过滤
if (wp_contains_private_data($_POST['comment_content'])) {
return 'spam';
}
return $approved;
});1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
📝 撰写设置
默认文章设置
php
// 设置默认分类
update_option('default_category', 1);
// 设置默认文章格式
update_option('default_post_format', 'standard');
// 设置每页文章数
update_option('posts_per_page', 10);1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
📁 媒体设置
php
// 在 wp-config.php 中设置
// 图片尺寸
update_option('thumbnail_size_w', 300);
update_option('thumbnail_size_h', 300);
update_option('thumbnail_crop', 1);
update_option('medium_size_w', 768);
update_option('medium_size_h', 0);
update_option('large_size_w', 1024);
update_option('large_size_h', 0);1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
🔒 隐私设置
创建隐私页面:
- 后台 → 页面 → 新建页面
- 标题:隐私政策
- 使用隐私政策模板
🌐 多站点配置
启用多站点
在 wp-config.php 中添加:
php
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);1
2
3
4
5
6
2
3
4
5
6
子目录模式 .htaccess
apache
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# 添加以下规则
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
📧 邮件配置
SMTP 配置
使用插件或代码:
php
// SMTP 配置 - functions.php
add_action('phpmailer_init', function($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.example.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->Username = 'noreply@example.com';
$phpmailer->Password = 'your_password';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->From = 'noreply@example.com';
$phpmailer->FromName = get_bloginfo('name');
});1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
🛡️ 安全配置
密钥配置
从 WordPress API 获取:
php
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
其他安全设置
php
// 禁用文件编辑
define('DISALLOW_FILE_EDIT', true);
// 禁用 PHP 错误显示
define('WP_DEBUG_DISPLAY', false);
// 自动更新
define('AUTOMATIC_UPDATER_DISABLED', false);
define('WP_AUTO_UPDATE_CORE', 'minor');1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
🎯 推荐配置清单
::: checklist 推荐配置
- [ ] 永久链接设置为文章名
- [ ] 禁用 XML-RPC
- [ ] 启用 HTTPS
- [ ] 设置管理员邮箱
- [ ] 配置 SMTP 邮件
- [ ] 设置隐私页面
- [ ] 配置备份策略
- [ ] 启用安全头 :::
