Skip to content

Instantly share code, notes, and snippets.

View glueckpress's full-sized avatar

Caspar Hübinger glueckpress

View GitHub Profile
@glueckpress
glueckpress / remove_theme_modifications.php
Last active December 14, 2015 21:51
[WordPress] Remove theme modifications (custom background, custom header, custom menus)
<?php
/* flush all theme modifications; check via get_theme_mods() */
// remove_theme_mods();
/* flush all but menus */
// remove_theme_mod('header_textcolor');
// remove_theme_mod('background_color');
// remove_theme_mod('background_image');
// remove_theme_mod('background_position_x');
// remove_theme_mod('background_attachment');
@glueckpress
glueckpress / php-to-js.php
Last active December 14, 2015 21:51
[WordPress] Basic routine to pass an array of values from PHP to JavaScript.
<?php
/* Create an array of data to pass */
$obj = array(
'foo' => $foo,
'bar' => $bar,
'multifoo' => array( 'foo1', 'foo2' )
);
/* Enqueue javascript (assuming jQuery has been enqueued already) */
@glueckpress
glueckpress / page-bulk-update-slugs.php
Last active April 28, 2019 11:19
[WordPress] Page template to bulk update page slugs with a given name scheme. USE WITH CAUTION! To avoid accidental re-slugging of pages, there’s $update_slugs_now set to false by default.
<?php
/*
Template Name: CAUTION - Bulk Update Page Slugs
SECURITY FEATURE: Will only update pages with a given author!
1. Create a new user with username "bulkupdater".
2. Assign all pages you need to update to author bulkupdater.
3. Create a new page, assign this template and open it in the browser.
4. You'll see a preview of what's going to happen.
5. Set $update_slugs_now to true and relaod the page in your browser to perform the update.
@glueckpress
glueckpress / sortable-media-author-column.php
Last active December 14, 2015 21:36
[WordPress] Make media library entries sortable by author column.
<?php
/**
* Make media author column sortable.
*/
add_filter( 'manage_upload_sortable_columns', 'gp130222_upload_sortable_columns' );
function gp130222_upload_sortable_columns( $columns ) {
array_push( $columns, $columns['author'] );
return $columns;
}
@glueckpress
glueckpress / .htaccess
Created April 5, 2013 08:30
Safari blocks HTML5 videos from playing if directory is protected via .htaccess. Solution: Allow direct access to video files. (Here: also image files.)
# Allow direct access to video and image files in a protected directory
# Props http://stackoverflow.com/a/9078460?stw=2
<FilesMatch "\.(mp4|ogv|webm|jpg|png)$">
Satisfy any
order allow,deny
allow from all
</FilesMatch>
@glueckpress
glueckpress / remove-file-versions-from-scripts.php
Last active December 16, 2015 10:39
[WordPress] Removes version queries from script/stylesheet calls in WordPress, but keeps query of google font stylesheets.
<?php
/**
* Removes file version queries from script/stylesheet calls.
* http://wordpress.stackexchange.com/a/96325/23011
*
* Enhanced to keep query of google font stylesheets:
* Removes “?ver=3.5.1” from http://domain.tld/wp-content/themes/theme/stlye.css?ver=3.5.1
* Leaves http://fonts.googleapis.com/css?family=MyFont untouched.
*/
add_filter( 'script_loader_src', 'gp130419_remove_script_version', 15, 1 );
@glueckpress
glueckpress / prepend-selector-to-nesting.scss
Created April 21, 2013 08:27
How to prepend i.e. a .js class to the first level of a nested selector in SASS.
/**
* Prepend a selector to the first level of nested selectors.
* Comments demonstrate compiled CSS.
*/
.foo {
/* .foo */
.bar {
/* .foo .bar */
@glueckpress
glueckpress / paginate-parent-children.php
Last active September 3, 2021 19:42
[WordPress] Pagination for a parent page and their child pages.
<?php
/**
* Pagination for a parent page and their child pages.
* Use as gp130428_link_pages() in your template file.
* Optionally limit to a particular parent page by passing its ID (i.e. 123) to the function: gp130428_link_pages( 123 )
*
*/
function gp130428_paginate_parent_children( $parent = null ) {
global $post;
@glueckpress
glueckpress / dynamic_copyright.php
Last active December 17, 2015 11:59
[WordPress] Dynamic copyright date depending on when the first post was published.
@glueckpress
glueckpress / px-rem-cheat-sheet.css
Created May 26, 2013 16:17
Cheat sheet for rem-calculations based upon 14px and 16px.
/*! = $rembase: 14px
--------------------------------------------------------------
* hmtl { font-size: 87.5%; }
* body { font-size: 14px; font-size: 1rem; line-height: 1; }
* 4px 0.28571429rem
* 8px 0.571428571rem
* 12px 0.857142857rem
* 13px 0.928571429rem
* 14px 1rem
* 16px 1.142857143rem