Skip to content

Instantly share code, notes, and snippets.

@peterwegren
peterwegren / 301s.php
Last active December 8, 2016 16:39
301s - WP Include File
<?php
$url = get_home_url();
// map redirects in array: [old url (path)] => [new url ($url + path)]
$redirect_urls = array(
// '' => $url . '',
);
/**
@peterwegren
peterwegren / helper_functions.php
Last active May 24, 2018 20:50
WP Helper Functions
<?php
/*
* Remove Dashboard Items
*/
if (is_admin()) {
if (!(function_exists('pl_remove_dash_items'))) {
function pl_remove_dash_items()
{
// Check that the built-in WordPress function remove_menu_page() exists in the current installation
@peterwegren
peterwegren / gfonts.txt
Last active October 6, 2016 17:24
Locally install all Google fonts.
curl https://raw.githubusercontent.com/qrpike/Web-Font-Load/master/install.sh | sh
@peterwegren
peterwegren / cpt-breadcrumbs.php
Last active November 16, 2016 17:21
Add CPT permalink base to breadcrumbs
<?php
/*
* Add CPT base to breadcrumbs
*/
function my_wpseo_breadcrumb_links( $links ) {
if ( is_single() ) {
$cpt_object = get_post_type_object( get_post_type() );
if ( ! $cpt_object->_builtin ) {
$landing_page = get_page_by_path( $cpt_object->rewrite['slug'] );
array_splice( $links, -2, 1, array( array( 'id' => $landing_page->ID ) ));
@peterwegren
peterwegren / printr.php
Last active November 16, 2016 17:21
Formatted variable printing function for debugging purposes.
<?php
/*
* Debugging @TODO: remove or comment out for production
*/
function printr($data) {
echo "<pre>";
print_r($data);
echo "</pre>";
}
@peterwegren
peterwegren / menu_item_class.php
Last active November 16, 2016 17:21
Menu item active class.
<?php
/*
* Menu item active class.
*/
function add_current_nav_class($classes, $item) {
// get current post details
global $post;
// get post type of current post
$current_post_type = !empty($post) ? get_post_type_object($post->post_type) : null;
@peterwegren
peterwegren / wp_init_cleanup.php
Last active December 1, 2016 16:09
Clear out some default WP settings on new installation.
<?php
/* modified from https://code.tutsplus.com/tutorials/how-to-activate-plugins-themes-upon-wordpress-installation--cms-23551 */
// set the options to change: https://codex.wordpress.org/Option_Reference
$option = array(
'blogdescription' => '',
'comments_notify' => 0,
'default_comment_status' => 'closed',
'default_ping_status' => 'closed',
@peterwegren
peterwegren / numeric_posts_nav.php
Last active October 3, 2018 04:49
Custom page/post pagination navigation.
<?php
/**
* numeric_posts_nav
* Custom numeric page links.
*
* @method numeric_posts_nav
*
* @author Peter Wegren <peter @ paper-leaf.com>
*
@peterwegren
peterwegren / select2_prevent_autofocus.js
Last active August 26, 2022 22:38
Prevent auto-focus on Select2 search input (prevents keyboard popup on Android).
// prevent auto-focus on select2 search input
$(document).ready(function(){
$('select').on('select2:open', function() {
$('.select2-search input').prop('focus', 0);
});
});
@peterwegren
peterwegren / select2_search_placeholder.js
Created December 5, 2016 17:45
Set Select2 search input placeholder text.
// #staff_name search input placeholder
$('select').on('select2:open', function() {
$('.select2-search--dropdown .select2-search__field').attr('placeholder', 'Type to search...');
});