Skip to content

Instantly share code, notes, and snippets.

View dartiss's full-sized avatar
🏠
Always working from home

David Artiss dartiss

🏠
Always working from home
View GitHub Profile
@dartiss
dartiss / functions.php
Last active October 23, 2018 11:32
List WordPress shortcodes
<?php
// Shortcodes to list all available shortcodes
function list_shortcodes() {
// Grab the global array of shortcodes
global $shortcode_tags;
// Sort the shortcodes into alphabetical order
@dartiss
dartiss / functions.php
Created November 14, 2017 15:59
No Self Pings
<?php
function no_self_pings( $links ) {
foreach ( $links as $loop => $link ) {
if ( 0 === strpos( $link, get_option( 'home' ) ) ) { unset( $links[ $loop ] ); }
}
}
add_action( 'pre_ping', 'no_self_pings' );
?>
@dartiss
dartiss / functions.php
Created November 14, 2017 16:03
Add a Time to Read To Your WordPress Posts
<?php
function time_to_read( $content = false ) {
if ( is_single () ) {
// If content has not been passed in (via the filter), fetch it
if ( !$content ) { $content = get_the_content(); $add = false; } else { $add = true; }
// Get the cache, if the content was not provided and this is not a preview
@dartiss
dartiss / functions.php
Created November 15, 2017 16:06
Remove WordPress version from header
<?php
function site_version_removal() { return ''; }
add_filter( 'the_generator', 'site_version_removal' );
?>
@dartiss
dartiss / functions.php
Created November 15, 2017 16:08
Allow Shortcodes in the Feed
<?php
add_filter( 'the_content_rss', 'do_shortcode' );
?>
@dartiss
dartiss / functions.php
Created November 15, 2017 16:11
Add Your Own Default Avatar to WordPress
<?php
function new_avatar( $avatar_defaults ) {
$new_avatar = content_url() . '/uploads/[your image]';
$avatar_defaults[ $new_avatar ] = 'No Avatar';
return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'new_avatar' );
?>
@dartiss
dartiss / functions.php
Created November 15, 2017 16:13
Show Post if Search Returns One Result
<?php
function single_result() {
if ( is_search() ) {
global $wp_query;
if ( $wp_query -> post_count == 1 && $wp_query -> max_num_pages == 1 ) {
wp_redirect( get_permalink( $wp_query -> posts[ 0 ] -> ID ) );
exit;
}
}
}
@dartiss
dartiss / functions.php
Last active November 15, 2017 16:18
Highlight Old WordPress Posts
<?php
function old_post_message( $content ) {
if ( get_the_time( 'U' ) < strtotime( '1st January 2013' ) ) {
$content = '<div class="alert alert-info alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Due to updates, over time, that have been made to the site and the age of this article, this post may not display correctly. In particular images may be missing or product reviews display incorrectly.</div>' . $content;
}
return $content;
}
add_filter( 'the_content', 'old_post_message' );
?>
@dartiss
dartiss / functions.php
Created November 15, 2017 16:28
Add a Default Image to Jetpack Related Posts
<?php
function jrp_custom_image( $media, $post_id, $args ) {
if ( $media ) {
return $media;
} else {
$permalink = get_permalink( $post_id );
$url = apply_filters( 'jetpack_photon_url', '[image url]' );
return array( array(
'type' => 'image',
@dartiss
dartiss / functions.php
Last active November 15, 2017 16:31
Do not add any context below each Jetpack Related Post
<?php
add_filter( 'jetpack_relatedposts_filter_post_context', '__return_empty_string' );
?>