Skip to content

Instantly share code, notes, and snippets.

View gareth-gillman's full-sized avatar

gareth-gillman

View GitHub Profile
@gareth-gillman
gareth-gillman / pe-customize-controls.css
Created February 15, 2017 00:45 — forked from OriginalEXE/pe-customize-controls.css
Extending WordPress Customizer Panels and Sections to allow nesting
.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel-parent,
#customize-theme-controls .customize-pane-child.current-section-parent {
-webkit-transform: translateX(-100%);
-ms-transform: translateX(-100%);
transform: translateX(-100%);
}
@gareth-gillman
gareth-gillman / header.php
Created February 9, 2017 18:03
Add logo to Twenty Seventeen Menu
<?php
/**
* The header for our theme
*
* This is the template that displays all of the <head> section and everything up until <div id="content">
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package WordPress
* @subpackage Twenty_Seventeen
@gareth-gillman
gareth-gillman / functions.php
Created December 21, 2016 16:02
Show only shop managers to a shop manager in WP Admin users
add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
$roles = wp_get_current_user();
if ( in_array( 'shop_manager', (array) $roles->roles ) ) {
global $wpdb;
$user_search->query_where =
str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
@gareth-gillman
gareth-gillman / functions.php
Created November 2, 2016 18:29
Add Page number to the WordPress page title for SEO benefits
function my_blog_number_title($titletag) {
if( is_paged() ) {
global $wp_query;
$pagenum = $wp_query->query_vars['paged'];
$new_title = $titletag.' Page '.$pagenum;
$titletag = str_replace($titletag, $new_title ,$titletag);
return $titletag;
}
}
add_filter('wp_render_title_tag_filter','custom_wp_render_title_tag');
@gareth-gillman
gareth-gillman / functions.php
Last active October 26, 2016 14:36
Custom Post Type WordPress Recent Posts Widget
<?php
class WP_Widget_NANE_Recent_Posts extends WP_Widget {
public function __construct() {
$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site&#8217;s most recent Posts.", "textdomain") );
parent::__construct('recent-posts', __('Recent Posts', 'textdomain'), $widget_ops, 'textdomain');
$this->alt_option_name = 'widget_recent_entries';
add_action( 'save_post', array($this, 'flush_widget_cache') );
add_action( 'deleted_post', array($this, 'flush_widget_cache') );
<ul>
<?php
$query_args = new WP_Query(
array(
'post_type' => 'attachment',
'posts_per_page' => -1,
)
);
if ( $query_args->have_posts() ) {
while ( $query_args->have_posts() ) : $query_args->the_post();
@gareth-gillman
gareth-gillman / jquery-check-target.js
Created August 30, 2016 10:19
Checks links on a website for the _blank attribute and adds the noopener and noreferrer tags if they don't exist - see https://dev.to/ben/the-targetblank-vulnerability-by-example
$(document).ready(function(){
$('a').each(function() {
if(
$(this).attr('target') == '_blank' ||
$(this).attr('rel') == 'noopener' ||
$(this).attr('rel') == 'noreferrer' ) {
$(this).attr('rel', 'noopener noreferrer');
}
});
});
@gareth-gillman
gareth-gillman / functions.php
Created August 27, 2016 13:20
WordPress Plugin Template Include
add_filter('template_include', 'my_function_name', PHP_INT_MAX, 2 );
function my_function_name( $template ) {
if(is_page('about')){
$template = dirname( __FILE__ ) . '/templates/about.php';
}
return $template;
}
@gareth-gillman
gareth-gillman / functions.php
Created August 8, 2016 10:27
Comment Email Notifications
function se_comment_moderation_recipients( $emails, $comment_id ) {
$emails = array( 'myemailk@mail.com' );
return $emails;
}
add_filter( 'comment_moderation_recipients', 'se_comment_moderation_recipients', 11, 2 );
add_filter( 'comment_notification_recipients', 'se_comment_moderation_recipients', 11, 2 );
@gareth-gillman
gareth-gillman / functions.php
Created August 1, 2016 11:23
WP Admin Focus Full Width
function admin_css() {
echo '<style>
.focus-on #wpcontent {
margin-left:0;
width:100%;
}
. .focus-on ##wpbody-content .metabox-holder{
width:100%;
}
.focus-on #poststuff #post-body.columns-2 {