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 / functions.php
Created May 19, 2016 13:56
Default Logo for WordPress Custom Logo (since 4.5)
add_filter('get_custom_logo', 'prefix_custom_logo_default', 10);
function prefix_custom_logo_default($html){
if(empty($html)){
$html = '<a href="'.esc_url(site_url()).'" class="custom-logo-link" rel="home" itemprop="url">';
$html .= '<img src="'.get_template_directory_uri() .'/images/logo.png" alt="Logo" class="custom-logo" itemprop="logo" />';
$html .= '</a>';
}
return $html;
}
@gareth-gillman
gareth-gillman / functions.php
Created May 19, 2016 13:58
Add custom class to WordPress Custom Logo (since 4.5)
add_filter('get_custom_logo', 'prefix_custom_logo_output', 10);
function prefix_custom_logo_output( $html ){
$html = str_replace( 'custom-logo-link', 'custom-logo-link navbar-brand', $html );
return $html;
}
@gareth-gillman
gareth-gillman / frontpage.php
Created June 13, 2016 13:48
FullpageJS in WordPress
<div id="fullpage">
<?php
$args = array(
'sort_column' => 'menu_order'
);
$pages = get_pages($args);
$i = 0;
foreach ( $pages as $page ) {
?>
@gareth-gillman
gareth-gillman / functions.php
Created June 16, 2016 20:22
WordPress comments Oembed
add_filter( 'comment_text', array( $wp_embed, 'run_shortcode' ), 8 );
add_filter( 'comment_text', array( $wp_embed, 'autoembed'), 8 );
@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 {
@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 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 / 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');
}
});
});
<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 / 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') );