Skip to content

Instantly share code, notes, and snippets.

View BruceMcKinnon's full-sized avatar

BruceMcKinnon

View GitHub Profile
@BruceMcKinnon
BruceMcKinnon / gist:8cdac576b6048d9e9f5f4c74ea0c4ba2
Created May 26, 2016 00:04
WP Provide first sentence only for the excerpt
add_filter(
'get_the_excerpt',
function ($excerpt) {
// Split the except into sentances
$re = '/(?<=[.!?]|[.!?][\'"])\s+/';
$sentences = preg_split($re, $excerpt, -1, PREG_SPLIT_NO_EMPTY);
return $sentences[0];
}
);
@BruceMcKinnon
BruceMcKinnon / gist:b11d8ac662d2328605f37074a0426da3
Created May 26, 2016 00:05
Override WP Pagination in FoundationPress
// Custom Pagination.
function foundationpress_pagination() {
global $wp_query;
$big = 999999999; // This needs to be an unlikely integer
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
'base' => str_replace( $big, '%#%', html_entity_decode( get_pagenum_link( $big ) ) ),
@BruceMcKinnon
BruceMcKinnon / gist:2d2fa922d81a78f1d35b3405684220f5
Created May 26, 2016 00:06
Override the WP post entry meta in FoundationPress
// Hook the post entry meta
function foundationpress_entry_meta() {
echo '<time class="updated" datetime="' . get_the_time( 'c' ) . '">' . sprintf( __( '%s', 'foundationpress' ), get_the_date() ) . '</time>';
}
@BruceMcKinnon
BruceMcKinnon / gist:307a322a36bf8b84d0d7f3ea5b8ac0af
Last active May 26, 2016 00:07
WP shortcode for displaying a fixed number of posts from a single category
function ccc_latest_post($atts, $content=null){
echo '<ul>';
$myposts = get_posts( array('posts_per_page' => 3, 'category_name' => 'news') );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<h4><a href="<?php echo get_the_permalink($post->ID); ?>"><?php echo get_the_title($post->ID); ?></a></h4>
<p><?php echo get_the_excerpt($post->ID); ?> <a href="<?php echo get_the_permalink($post->ID); ?>"><em>Read more...</em></a></p>
</li>
<?php endforeach;
wp_reset_postdata();
@BruceMcKinnon
BruceMcKinnon / gist:af4b80a5c9a30a1ff30f4acaac2ac3ff
Created May 26, 2016 00:08
WP breadcrumbs for FoundationPress
//
// Add Breadcrumbs
//
function ccc_breadbrumbs() {
if ( !(is_home() || is_front_page()) ) {
echo '<div class="row"><div class="small-12 columns">';
// Call the standard FP breadcrumb
foundationpress_breadcrumb();
echo '</div></div>';
}
@BruceMcKinnon
BruceMcKinnon / gist:b82856f5b0c35526dfc2f2f51e5cbdd7
Created May 26, 2016 00:09
WP add categories and tags for attachments and media objects
//
// add categories for attachments
//
function add_categories_for_attachments() {
register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'add_categories_for_attachments' ); // add tags for attachments function
function add_tags_for_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
@BruceMcKinnon
BruceMcKinnon / gist:7e336361ce0ed42e19c793aa52d4a516
Created May 26, 2016 00:09
WP auto-hide the toolbar for users
//
// Auto hide the WP toolbar for users
//
add_filter('show_admin_bar', '__return_false');
@BruceMcKinnon
BruceMcKinnon / gist:e7c4d42e9254437d203e0da863fe3607
Created May 26, 2016 00:12
htaccess block WP admin pages by IP address
# Block access to wp-admin.
order deny,allow
# Allow one IP address
allow from z.z.z.z
# Allow from a range of IP addresses
allow from x.x.x.x/24
allow from y.y.y.y/27
@BruceMcKinnon
BruceMcKinnon / gist:0cacf0a9a732a0d8782fe9edcf643030
Last active February 15, 2022 22:03
htaccess auto redirect to SSL connection
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
@BruceMcKinnon
BruceMcKinnon / closed.html
Created September 4, 2017 22:45
Web Site Closed
<!DOCTYPE html>
<html>
<title>Web Site Closed</title>
<meta charset="UTF-8">
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<style>
body,h1 {font-family: "Raleway", sans-serif}
body, html { height: 100%; color: #ffffff; background-color: #191919; text-align: center; overflow:visible; }