本来google的插件是很好用的,但无奈我的wordpress主题好像有问题,安装Google XML Sitemaps
后,访问sitemap.xml页面会报错:
error on line 2 at column 6: XML declaration allowed only at the start of the document
如果你也有遇到过同样的问题,并且你有好的解决方案,欢迎与我分享~
于是我们利用python手动生成网站的sitemap。
从Github上克隆python-sitemap
:
git clone https://github.com/c4software/python-sitemap.git
vim get_sitemap.sh
:# 运行main.py,且输出sitemap.xml放到wordpress根目录下
/usr/bin/python3 /root/python-sitemap/main.py --domain https://weiweiblog.cn --output /var/www/wordpress/sitemap.xml
# 打印时间
echo "new sitemap get! --" + `date`
crontab -e
添加下面一行
# 每天01:01分更新
1 1 * * * bash /root/python-sitemap/get_sitemap.sh >> /root/python-sitemap/crontab.log 2>&1
这样,就可以每天自动更新网站的sitemap.xml文件了。