Skip to content

Instantly share code, notes, and snippets.

View glueckpress's full-sized avatar

Caspar Hübinger glueckpress

View GitHub Profile
@glueckpress
glueckpress / wp-shortcode-email-link.php
Last active December 14, 2015 21:51
[WordPress] Concise shortcode function for an anti-spambotted email link in WordPress. Parameters for class, style (check for support in your wysiwyg editor!) and title attributes. Parameters before, after, before_text and after_text for most concise control of the final HTML output.
@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 / .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 / dynamic_copyright.php
Last active December 17, 2015 11:59
[WordPress] Dynamic copyright date depending on when the first post was published.
@glueckpress
glueckpress / wp-ie-conditional-comment-syntax-hack.php
Last active December 19, 2015 12:39
[WordPress] @2ndkauboy has a nice hack to conditionally generate an IE legacy stylesheet with SASS and load it conditionally (http://kau-boys.de/1747) (post in German). This solution tweaks WordPress’s syntax for conditional comments accordingly.
<?php
/**
* Read first, otherwise the following will make no sense at all:
* http://kau-boys.de/1747
*
*
* WordPress’s built-in conditional comment syntax allows
* for conditional comments like this:
*
* <!--[if gt IE 8]>
@glueckpress
glueckpress / single-select-form.html
Created July 14, 2013 14:24
Single select form with custom styles and arrow (incl. work-around for Mozilla select arrow bug). Form selector element could also be substituted by a wrapping span or div element for forms with multiple fields.
<form class="ordering" method="get">
<select name="name">
<option value="value">Option</option>
<option value="value">Option</option>
<option value="value">Option</option>
</select>
</form>
@glueckpress
glueckpress / wp-modify-text-strings.php
Last active December 21, 2015 00:19
[WordPress] Modify default (not translated) language strings of a plugin. Beware: Might result in performance issues when applied to many strings.
<?php
/**
* Translate text strings in WordPress programmatically.
*
* Assuming plugin intorduces "Foo_Plugin" class, has text domain "foo-plugin".
*
* @param mixed $translated
* @param mixed $original
* @param mixed $domain
* @return string