730 字
4 分钟
wordpress个人自定义
哀悼纪念日
html {filter: grayscale(100%);-webkit-filter: grayscale(100%);-moz-filter: grayscale(100%);-ms-filter: grayscale(100%);-o-filter: grayscale(100%);}放置到 外观→自定义→额外 css
代码完整显示
article pre.wp-block-code code{ max-height: 100%!important;}放置到 外观→自定义→额外 css
保护后台登录
//保护后台登录add_action('login_enqueue_scripts','login_protection');function login_protection(){if($_GET['hello'] != 'Tr4gg9Y3gBUX')header('Location: http://任意其他网站或者网站首页/');}将上方的代码添加至 WordPress 当前使用主题文件夹下的 functions.php 文件即可 这样只有打开 你的网站/wp-login.php?hello=Tr4gg9Y3gBUX 才会打开登录页,否则就会自动跳转到后面的网站
WordPress 彻底禁用上传媒体图片自动生成缩略图及多尺寸图片
// 禁用自动生成的图片尺寸function shapeSpace_disable_image_sizes($sizes) {unset($sizes['thumbnail']); // disable thumbnail sizeunset($sizes['medium']); // disable medium sizeunset($sizes['large']); // disable large sizeunset($sizes['medium_large']); // disable medium-large sizeunset($sizes['1536x1536']); // disable 2x medium-large sizeunset($sizes['2048x2048']); // disable 2x large sizereturn $sizes;}add_action('intermediate_image_sizes_advanced', 'shapeSpace_disable_image_sizes');// 禁用缩放尺寸add_filter('big_image_size_threshold', '__return_false');// 禁用其他图片尺寸function shapeSpace_disable_other_image_sizes() {remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size()remove_image_size('another-size'); // disable any other added image sizes}add_action('init', 'shapeSpace_disable_other_image_sizes');将上方的代码添加至 WordPress 当前使用主题文件夹下的 functions.php 文件即可
给 WordPress 文章 ID 重新排序
原文地址:https://fairysen.com/171.html > ✅ 先备份数据库 > 💡删除冗余的修订版本和自动保存 插件使用 WP-Sweep 或 手动清除代码:
DELETE a,b,cFROM wp_posts aLEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)WHERE a.post_type = 'revision';DELETE FROM wp_postmeta WHERE meta_key = '_edit_lock';DELETE FROM wp_postmeta WHERE meta_key = '_edit_last';重新排列不连续的文章 ID 复制 php 脚本代码至 id.php,上传到你主机根目录下 访问:http://你的网站域名/id.php ,即可达到重新排序的效果,从 1开始。 > ✅同时修改https://onepve.com 为你的域名
<?php /** https://fairysen.com/171.html *//** 引入网站配置文件,这里主要获得数据库连接信息及常规操作类 */require_once './wp-config.php';function change_post_id($id){ global $convertedrows, $wpdb; /** 修改文章ID关联的类别、标签、自定义字段、评论各表,prefix是您安装时设置的数据库表前缀 */ $wpdb-?>query('update ' . $wpdb->prefix . 'posts set ID = ' . $convertedrows . ' where ID = ' . $id); $wpdb->query('update ' . $wpdb->prefix . 'posts set guid = https://onepve.com/?p=' . $convertedrows . ' where ID = ' . $convertedrows . ' and post_type = post'); $wpdb->query('update ' . $wpdb->prefix . 'term_relationships set object_id = ' . $convertedrows . ' where object_id = ' . $id); $wpdb->query('update ' . $wpdb->prefix . 'postmeta set post_id = ' . $convertedrows . ' where post_id = ' . $id); $wpdb->query('update ' . $wpdb->prefix . 'comments set comment_post_ID = ' . $convertedrows . ' where comment_post_ID = ' . $id); $convertedrows++;}/** ID默认由1开始 */$convertedrows = 1;/** 查询数据库文章表所有记录 */$sql_query = 'SELECT ID FROM ' . $table_prefix . 'posts ORDER BY ID ASC';//echo '' . $sql_query . '\n';$all_post_ids = $wpdb->get_results($sql_query);/** 有返回值时则执行循环 */if (is_array($all_post_ids)) { foreach ($all_post_ids as $post_id) { change_post_id($post_id->ID); }}/** 重新设置文章ID自动增加的起点 */$wpdb->query('alter table ' . $table_prefix . 'posts AUTO_INCREMENT = ' . $convertedrows);echo 'Total:' . $convertedrows . ', It\'s ok!!! ';