Skip to content

Instantly share code, notes, and snippets.

View malinky's full-sized avatar

Craig Ramsay malinky

View GitHub Profile
@malinky
malinky / gist:7fb1bbf9febe8743c98f
Last active August 29, 2015 14:12
Loop Counters
/**
* Bitwise Check
* If $count is an odd number returns true (1st expression).
*/
echo $count & 1 ? '' : '' ;
/**
* Bitwise Check Usage
* Add a class 'end' on every even loop (when expression returns false).
*/
@malinky
malinky / gist:d08b1ac902b11847a2c1
Last active August 29, 2015 14:13
Setting up and Running Shell Script
# Open terminal stay in home directory.
# Running first command results in Permission Denied error so we need to make script executable.
# The commmands ls -l are used to check permissions have been changed.
# Change back to home directory to show script will run from anywhere.
filename.sh
cd /usr/local/bin
ls -l
chmod +x filename.sh
ls -l
@malinky
malinky / gist:e7fb7e4a757c4bbd5acc
Last active August 29, 2015 14:13
Add to $PATH
# Manually add to $PATH.
# Open ~/.bash_profile or /Users/USERNAME/.bash_profile
# Add the below line and amend PATHTODIRECTORY. Use "" if there are spaces in any directories.
# Seperate multiple additions with :
# Restart Terminal test with echo $PATH.
export PATH=$PATH:PATHTODIRECTORY
@malinky
malinky / gist:0dd23c817d2b6129cc13
Created January 15, 2015 09:27
Position absolute, fixed height, centered header image
/*
* 1. Position if underneath a fixed navigation.
* 2. Set to image height.
*/
.header-image {
position: absolute;
overflow: hidden;
top: px /* 1 */
left: 0;
width: 100%;
@malinky
malinky / gist:ff7c451e102de81920d9
Created January 19, 2015 09:20
Allow SVG into WP Media Uploader
/**
* Allow SVG into media uploader.
*/
function malinky_mime_types( $mimes )
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'malinky_mime_types');
@malinky
malinky / gist:4899384e1de5e4ab3338
Last active September 29, 2019 01:50
Wordpress Custom Post Type Landing Pages
/**
* Wordpress Custom Post Type Landing Pages
* In all examples $rewrite and $args are simplified to the discussed settings.
*/
/**
* 1. Custom Post Type has archives and the slug is rewritten.
* In this case a visit to /post-type-name will use archive-$posttype.php, $archive.php, index.php.
* Pagination will work by default assuming $rewrite[ 'pages' ] is also true (default).
* It's not possible to create a landing page called /post-type-name as the archive page controls the template hierarchy.
@malinky
malinky / gist:0b747d74b1abb8a72618
Last active April 27, 2022 22:24
Wordpress Custom Post Type - Archive and Landing Page Variations
/* ------------------------------------------------------------------------ *
* Custom post type and taxonomy with archives. (Preferable URLS)
* ------------------------------------------------------------------------ */
/**
* No landing page added to admin.
* Use archive template hierarchy to create a landing page if requried.
* No custom wp_query is requried for pagination, it just works.
* Obviously need to add post_type_link filter for the URLS to include the taxonomy.
* As there is no landing page harder to add to a menu. https://wordpress.org/plugins/post-type-archive-links/
RewriteEngine On
# Redirect a specific page. Includes optional trailing slash.
# Both rules go to the same page on the same domain.
# If not using the protocol on the redirect remember the opening slash.
# RewriteRule ^djs/meatkatie(/)?$ http://www.domain.co.uk/dj-listings/meatkatie [R=301,L]
# RewriteRule ^djs/meatkatie(/)?$ /dj-listings/meatkatie [R=301,L]
# Redirect whole directory. Includes optional trailing slash.
# RewriteRule ^djs(/)?(.*)$ http://www.domain.co.uk/dj-listings [R=301,L]
@malinky
malinky / gist:2bf6430cd6deedee4ff8
Last active August 29, 2015 14:14
Function Declarations and Expressions
/**
* See http://benalman.com/news/2010/11/immediately-invoked-function-expression/ for a better explanation
*/
<script>
function test() {
console.log('function declaration that is called with test()');
}
test();
(function test() {
console.log('immediately invoked function declaration wrapped in brackets (turned into an expression)');
@malinky
malinky / gist:bff000432a1551085447
Created February 12, 2015 10:06
Wordpress DB Cleanup
/* Delete revisions */
DELETE FROM wp_posts WHERE post_type = "revision";
/**
* Also set in wp-config.php
* define( 'WP_POST_REVISIONS', 3 );
*/
/* Clean postmeta where the associated post no longer exists */
SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;