Skip to content

Instantly share code, notes, and snippets.

View danielck's full-sized avatar

Daniel Koskinen danielck

View GitHub Profile
@danielck
danielck / condional-sidebar.php
Last active December 15, 2015 07:49
WordPress sidebar example. Conditional loading of a dynamic sidebar or a link, based on a custom variable.
<div id="sidebar">
<?php
// Check for the 'part' variable
$part = get_query_var('part');
// If this is a sidebar, show the dynamic content
if ( $part == 'sidebar' ) :
?>
// Load asides
var asideLoader = $('#load-asides');
var asideContainer = $('#sidebar');
var loadAsides = function () {
var href = asideLoader.attr('href');
asideContainer.load( href + ' #sidebar-content');
}
asideContainer.on( 'click', '#load-asides', function(e) {
e.preventDefault();
loadAsides();
} );
<?php
/**
* Add a new /part/ endpoint. Access the value of part by
* using get_query_var( 'part' ) in a theme template.
*/
add_filter( 'init', 'h1ep_add_rules' );
function h1ep_add_rules() {
// this will register the endpoint for all WordPress URLs
add_rewrite_endpoint( 'part', EP_ALL );
}
<?php
/**
* Returns the localised slug for a taxonomy term
*/
function h1_term_slug( $slug, $taxonomy, $return_original_if_missing = true ) {
$localized_term = h1_get_term_by( 'slug', $slug, $taxonomy, OBJECT, 'raw', $return_original_if_missing );
if ( $localized_term && !is_wp_error( $localized_term ) ) {
$slug = $localized_term->slug;
@danielck
danielck / .gitignore
Last active February 8, 2017 07:59 — forked from salcode/.gitignore
WordPress .gitignore - this is my preferred gitignore file when working with WordPress. It ignores almost all files by default.
# -----------------------------------------------------------------
# .gitignore for WordPress (based on original from @salcode)
#
# By default all files are ignored. You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
#
# To ignore uncommitted changes in a file that is already tracked, use
# git update-index --assume-unchanged
#
# To stop tracking a file that is currently tracked, use
@danielck
danielck / polylang-bulk-translate.php
Created March 13, 2017 11:36 — forked from tnottu/polylang-bulk-translate.php
WP Polylang Bulk Translate
<?php
/*
Plugin Name: Polylang Bulk Translate
Plugin URI:
Version: 0.1.0
Author: Tyomaa Oy
Author URI: https://github.com/tnottu
Description: Translate multiple posts with bulk actions
License: GPLv2 or later
@danielck
danielck / customizer-preview.js
Last active March 16, 2021 11:19
Some basic Customizer examples
/*
Include this file in your theme and enqueue it like this in PHP:
function my_customize_preview_js() {
wp_enqueue_script( 'customizer-preview', get_template_directory_uri() . '/path/to/customizer.js', array( 'customize-preview' ), '20170422', true );
}
add_action( 'customize_preview_init', 'my_customize_preview_js' );
*/
@danielck
danielck / migrate-comments.php
Created May 12, 2017 10:58
WP-CLI script to migrate comment likes from Comments Rating Pro to WP Ulike
<?php
/*
Plugin Name: Migrate comment likes
Version: 0.1
Description: Migrate comment likes from WP Comment Rating Pro to Ulike
Author: Daniel Koskinen / Zeeland Family
Author URI: http://wordpress.zeelandfamily.fi/
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
@danielck
danielck / merge_asana_into_omnifocus.rb
Created May 29, 2017 05:48 — forked from hiltmon/merge_asana_into_omnifocus.rb
Updated Merge Asana into OmniFocus script
#!/usr/bin/env ruby -E utf-8
# merge_asana_into_omnifocus.rb
# Hilton Lipschitz
# http://www.hiltmon.com
# Use and modify freely, attribution appreciated
# Script to import Asana projects and their tasks into
# OmniFocus and keep them up to date from Asana.