Skip to content

Instantly share code, notes, and snippets.

View glueckpress's full-sized avatar

Caspar Hübinger glueckpress

View GitHub Profile
@glueckpress
glueckpress / foo-custom-text-strings.php
Last active December 14, 2015 21:33
[WordPress] Mini example plugin. Modify default (not translated) language strings of a plugin. Beware: Might result in performance issues when applied to many strings.
<?php
/**
* Plugin Name: Custom Text Strings for Foo Plugin
* Description: Modify default (not translated) language strings of a plugin. Beware: Might result in performance issues when applied to many strings.
* Version: 2014.10
* Author: Caspar Hübinger
* Author URI: http://glueckpress.com/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
@glueckpress
glueckpress / glckprss-sticky-posts.php
Last active December 14, 2015 21:33
[WordPress] Removes sticky posts from WordPress default loop, sets up a custom sticky posts query. Sticky posts query can be implemented with one single template tag. Markup completely filterable. — http://glck.be/5916/
<?php
/**
* Separate sticky posts from the main loop into their own query.
*
* Display a query of sticky posts anywhere in your templates
* using a simple echo glckprss_sticky_posts().
* Query template output is stored in a transient for performance win,
* updated any time the 'sticky_posts' option get updated.
*
* Require in theme’s functions.php like:
@glueckpress
glueckpress / real-favicons.php
Last active December 14, 2015 21:34
[WordPress] Mini plugin, adds favicons, touch icons and tiles for desktop browsers, iOS, Android and Windows. Generated HTML output via http://realfavicongenerator.net/. Requires a sub-directory /img to store all images in. HEADS UP: This is no longer needed as of WordPress 4.3!
<?php
/**
* Plugin Name: Real Favicons
* Description: Adds favicons, touch icons and tiles for desktop browsers, iOS, Android and Windows. Generate HTML output via <a href="http://realfavicongenerator.net/">realfavicongenerator.net</a>. Store all generated images in sub-directory /img.
* Version: 2014.01
* Author: Caspar Hübinger
* Author URI: http://glueckpress.com/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
@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 / glckprss-reduce-tags.php
Last active December 14, 2015 21:38
[WordPress] Mini plugin to reduce the number of tags displayed in the Tag Cloud widget.
<?php
/**
* Plugin Name: GlückPress Reduce Tags
* Description: Reduce the number of tags displayed in the tag cloud widget.
* Version: 2014.01
* Author: Caspar Hübinger
* Author URI: http://glueckpress.com/
*
*/
@glueckpress
glueckpress / child-theme-functions.php
Last active December 14, 2015 21:39
[WordPress] Parent/child theme l10n logic.
<?php
/**
* child-theme/functions.php
*
* Loads first, before parent-theme/functions.php.
*/
function child_after_setup_theme() {
load_child_theme_textdomain( 'child-textdomain', get_stylesheet_directory() . '/languages' );
@glueckpress
glueckpress / content-product.php
Last active December 14, 2015 21:39
[WordPress] WooCommerce: Display product variation attributes on product category pages.
<?php
/*
* Regular content of content-product.php
* ...
* ...
*/
/**
* Display product variation attributes on product category pages.
*
@glueckpress
glueckpress / wp-is-login.php
Last active December 14, 2015 21:42
[WordPress] Conditional tag to check whether current page is wp-login.php or wp-register.php.
<?php
/**
* Conditional tag to check whether current page is wp-login.php or wp-register.php.
*/
if( ! function_exists( 'wp_is_login' ) ) {
function wp_is_login() {
return in_array( $GLOBALS[ 'pagenow' ], array( 'wp-login.php' , 'wp-register.php' ) );
}
}
@glueckpress
glueckpress / current-attachment-nav-class.php
Last active December 14, 2015 21:50
[WordPress] Add current ancestor class to nav menu when viewing a singular attachment page, e.g. via the image.php template file.
<?php
/**
* Add current item classes for attachment views
*/
function _s_current_attachment_nav_class( $classes, $menu_item ) {
global $wp_query, $post;
if( true == $wp_query->is_singular && 'attachment' == $post->post_type && in_array( $menu_item->object_id, $post->ancestors ) ) {
$classes[] = 'current-menu-ancestor';
@glueckpress
glueckpress / page-dynamically-named-sidebar.php
Last active December 14, 2015 21:50
[WordPress] Call a registered sidebar in a page template dynamically based on the page slug.
<?php
// This whole thing goes into a page template,
// so we can get the page object via the_post() here
global $wp_query;
the_post();
// Store page slug for later
$gp_current_page_slug = $post->post_name;
// Page content