Skip to content

Instantly share code, notes, and snippets.

View jamesmorrison's full-sized avatar

James Morrison jamesmorrison

View GitHub Profile
@jamesmorrison
jamesmorrison / custom-wordpress-loop
Created August 11, 2012 17:55
Custom WordPress Loop
<?php
$custom_args = array(
// Declare your parameters. For example:
'post_type' => 'post',
'posts_per_page' => '4',
'orderby' => 'date',
'order' => 'DESC'
<?php
/**
* Usage:
* Paste a gist link into a blog post or page and it will be embedded eg:
* https://gist.github.com/2926827
*
* If a gist has multiple files you can select one using a url in the following format:
* https://gist.github.com/2926827?file=embed-gist.php
*/
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
<?php
/*-------------------------------------------------------------------------------------------------------------------------
WordPress Config Master
-------------------------------------------------------------------------------------------------------------------------*/
// PHP Info
@jamesmorrison
jamesmorrison / .htaccess-wpms-subdirectory
Created March 18, 2015 20:07
WordPress Multisite, WP in sub-folder, wp-content at root level
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
<?php
/**
* keeps a user always logged in
* don't use this on a production site, ever!
*/
add_action('init', 'auto_login');
add_action('admin_init', 'auto_login');
function auto_login() {
<?php
/*
* Force URLs in srcset attributes into HTTPS scheme.
*/
add_filter( 'wp_calculate_image_srcset', function( $sources ) {
foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'], 'https' );
}
@jamesmorrison
jamesmorrison / wordpress-random-post-slug.php
Last active June 7, 2021 04:56
Replace the default WP post slug with a random one in the format is "XXXX-XXXX-XXXX-XXXX"
<?php
/**
*
* Filter post slug
* This needs saving as post meta to use that value rather than regenerate a new one
*
**/
add_filter( 'wp_unique_post_slug', function( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
<?php
function _get_current_page_url() {
global $wp;
return esc_url( home_url( $wp->request ) );
}
@jamesmorrison
jamesmorrison / wp-ms-allow-self-signed-ssl.php
Created May 24, 2016 13:27
Allow self signed SSL on WP (required when doing network upgrade)
<?php
if ( defined( 'LOCAL_DEV' ) && LOCAL_DEV ) {
// Allow Self Signed SSL Certificates
add_filter('https_ssl_verify', '__return_false');
add_filter('https_local_ssl_verify', '__return_false');
}