Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / .htaccess
Last active April 16, 2022 20:26
Redirect an old domain to a new domain with .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
@wpscholar
wpscholar / wp-login-redirect.php
Last active November 22, 2018 17:39
WordPress function for redirecting users based on custom user meta
<?php
/**
* WordPress function for redirecting users based on custom user meta
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( 'cool' == get_user_meta( $user->ID, '_is_cool', true ) ) {
$url = home_url('/cool-people-only/');
}
@wpscholar
wpscholar / bullets.css
Last active December 11, 2015 22:08
Make bullets a different color without effecting list item text.
/**
* Make bullets a different color without effecting list item text.
* Works in all browsers including IE8+
*/
li {
list-style-type: none;
padding-left: 20px;
text-indent: -20px;
}
li:before {
@wpscholar
wpscholar / replace-wp-dashboard.php
Last active December 3, 2024 23:58
Replace the default WordPress dashboard with a custom one
<?php
/**
* Plugin Name: Replace WordPress Dashboard
* Description: Replaces the default WordPress dashboard with a custom one.
* Author: Micah Wood
* Author URI: http://micahwood.me
* Version: 0.1
* License: GPL3
*/
@wpscholar
wpscholar / functions.php
Last active October 20, 2024 14:01
Enqueueing IE conditional stylesheets in WordPress the right way
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_my_styles' );
/**
* Example callback function that demonstrates how to properly enqueue conditional stylesheets in WordPress for IE.
* IE10 and up does not support conditional comments in standards mode.
*
* @uses wp_style_add_data() WordPress function to add the conditional data.
* @link https://developer.wordpress.org/reference/functions/wp_style_add_data/
@wpscholar
wpscholar / ie-conditional-comment.html
Created February 17, 2013 06:06
Sample IE conditional comment
<!--[if lt IE 9]>
<link href="style.css" rel="stylesheet" type="text/css">
<![endif]-->
@wpscholar
wpscholar / functions.php
Created February 17, 2013 06:27
An OK way to handle loading of IE conditional stylesheets in WordPress.
<?php
add_action( 'wp_print_styles', 'print_my_styles' );
function print_my_styles() {
echo '<!--[if lt IE 9]><link href="style.css" rel="stylesheet" type="text/css"><![endif]-->';
}
@wpscholar
wpscholar / reorder-posts.php
Created February 18, 2013 18:14
Easily reorder pages / posts in WordPress
<?php
function reorder_posts( $order = array() ) {
global $wpdb;
$list = join(', ', $order);
$wpdb->query( 'SELECT @i:=-1' );
$result = $wpdb->query(
"UPDATE wp_posts SET menu_order = ( @i:= @i+1 )
WHERE ID IN ( $list ) ORDER BY FIELD( ID, $list );"
);
@wpscholar
wpscholar / shortcode.class.php
Last active September 20, 2017 23:27
Creating a class to handle a WordPress shortcode is overkill in most cases. However, it is extremely handy when your shortcode requires helper functions.
<?php
/**
* Creating a class to handle a WordPress shortcode is overkill in most cases.
* However, it is extremely handy when your shortcode requires helper functions.
*/
class My_Shortcode {
protected
$atts = array(),
@wpscholar
wpscholar / bootstrap.php
Created March 8, 2013 00:06
PHPUnit WordPress bootstrap file
<?php
/**
* Installs WordPress for running the tests and loads WordPress and the test libraries
*/
error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
require_once 'PHPUnit/Autoload.php';
$config_file_path = dirname( __FILE__ ) . '/wp-tests-config.php';