Skip to content

Instantly share code, notes, and snippets.

@andandehei
andandehei / password-resetter.php
Created October 29, 2014 14:16
wordpress教程:wordpress忘记密码后重置用户名及密码
<?php
//password resetter
include("wp-config.php");
include("wp-blog-header.php");
if (empty($_POST['emergency_pass'])) {
?>
<form method="post">
set admin password: <input name="emergency_pass" type="password" />
<input type="submit" />
</form>
@andandehei
andandehei / yasuo.php
Last active November 13, 2017 12:23
wordpress加速:纯代码方法压缩wordpress网页代码
<?php
/*
*压缩html代码
*/
function wp_compress_html()
{
function wp_compress_html_main ($buffer)
{
$initial=strlen($buffer);
@andandehei
andandehei / 获取文章中第一张图片并显示图片 代码预留
Last active August 29, 2015 13:56
获取文章中第一张图片并显示图片 代码预留
①将以下代码粘贴到functions.php文件中。
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
//获取文章中第一张图片的路径并输出
@andandehei
andandehei / ad1_button.php
Last active January 3, 2016 14:19
wordpress教程:怎么再wordpress编辑器里添加新的按钮
<? php
//1.在当前主题的functions.php文件中粘贴以下代码:
//初始化时执行ad1_button函数
add_action('init', 'ad1_button');
function ad1_button() {
//判断用户是否有编辑文章和页面的权限
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
return;
}
//判断用户是否使用可视化编辑器
@andandehei
andandehei / google-search.php
Last active January 3, 2016 13:09
wordpress教程:wordpress网站添加谷歌Google站内搜索 所用到的代码
<? php
//第一次代码
<script type="text/javascript">
google.load('search', '1', {language : 'zh-CN'});
google.setOnLoadCallback(function(){
var customSearchControl = new google.search.CustomSearchControl('003292911367075971799:8iziecydkbw');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
var match = location.search.match(/q=([^&]*)(&|$)/);
if(match && match[1]){
@andandehei
andandehei / wenchenhk_index_html.php
Last active November 15, 2017 14:17
wordpress加速:首页静态化超强提高wordpress速度
//将以下代码复制到index_html.php文件中,然后上传到网站根目录下
<?php
$baseCmsUrl = "http://www.wenchenhk.com";
$dmPageName = "index.php";
$stPageName = "index.html";
$tureStFile = dirname(__FILE__).'/'.$stPageName;
{
$body = file_get_contents($baseCmsUrl.'/'.$dmPageName);
$fp = fopen($tureStFile, 'w');
fwrite($fp, $body);
@andandehei
andandehei / wenchenhk_get_post.php
Last active January 3, 2016 07:59
代码实现本篇文章的前几篇和后几篇功能
<? php
//前几篇后几篇文章
function wenchenhk_get_post( $previous = true, $number = 1 ) {
//global当前文章变量 $post 和数据库操作类wpdb
global $post, $wpdb;
if ( empty( $post ) )
return null;
$current_post_date = $post->post_date;//当前文章的时间
@andandehei
andandehei / my_remove_recent_comments_style.php
Last active November 15, 2017 14:17
wordpress 加速:代码实现对wp_head()函数的优化
<? php
//优化head()函数
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
@andandehei
andandehei / wenchenhk_login_message.php
Last active January 3, 2016 05:59
wordpress教程:后台登陆页面添加自定义信息框
<? php
//自定义登陆页面信息
function wenchenhk_login_message( $message ) {
if ( empty($message) ){
return "<p class='message'>这个地方加入想要的提示信息</p>";
} else {
return $message;
}
}
add_filter( 'login_message', 'wenchenhk_login_message' );
@andandehei
andandehei / programmatic_login.php
Last active January 3, 2016 05:59
wordpress后台登陆限制功能
<? php
/**
* Programmatically logs a user in
*
* @param string $username
* @return bool True if the login was successful; false if it wasn't
*/
function programmatic_login( $username ) {
if ( is_user_logged_in() ) {