Skip to content

Instantly share code, notes, and snippets.

Aaron Summers aaronsummers

Block or report user

Report or block aaronsummers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View dirty-excerpt.php
<?php
$excerpt = get_the_excerpt();
echo ( strlen($excerpt) > 40 ) ? mb_substr($excerpt, 0, 40, "utf-8") ."..." : $excerpt;
@aaronsummers
aaronsummers / import database.bash
Created Oct 9, 2019
Terminal import database into mamp
View import database.bash
/Applications/MAMP/Library/bin/mysql -u root -p {DB_NAME} < {PATH/TO/MYSQL/DUMP/FILE.SQL}
@aaronsummers
aaronsummers / url_replace.sql
Last active Oct 9, 2019
updating wordpress site url with SQL in phpMyAdmin
View url_replace.sql
SET @FIND_URL = `old_url`;
SET @REPLACE_URL = `new_url`;
UPDATE wp_options SET option_value = replace(option_value, @FIND_URL, @REPLACE_URL) WHERE option_name = `home` OR option_name = `siteurl`;
UPDATE wp_posts SET guid = replace(guid, @FIND_URL, @REPLACE_URL);
UPDATE wp_posts SET post_content = replace(post_content, @FIND_URL, @REPLACE_URL);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @FIND_URL, @REPLACE_URL);
@aaronsummers
aaronsummers / language-switch.js
Created Sep 30, 2019
Marionnaud MCH language script
View language-switch.js
if (location.pathname.indexOf('/fr/') > -1) {
// Add french stuff here
} else {
// Add other content here
}
@aaronsummers
aaronsummers / metabox-shortcode.php
Created Jul 30, 2019
Add a metabox displaying a shortcode with the current posts ID
View metabox-shortcode.php
function shortcode_output() {
global $post;
// Get the data
$id = $post->ID;
// Echo out the field
echo '<input type="text" name="_id" value="[elab_gallery id=' . $id . ']" class="widefat" readonly />';
}
@aaronsummers
aaronsummers / all-images.php
Created Jul 30, 2019
Get all images from a post
View all-images.php
$post = get_post( get_the_ID() );
$content = $post->post_content;
$regex = '/src="([^"]*)"/'; // Find all the images
preg_match_all( $regex, $content, $matches );
$embedded_images_count = count( $matches[0] );
echo '<pre>' . var_export($matches, true) . '</pre>';
if ( $embedded_images_count > 0 ) {
for ( $i=0; $i < $embedded_images_count ; $i++ ) {
$img_src = $matches[0][$i];
$trim_front = ltrim($img_src, 'src="');
@aaronsummers
aaronsummers / function-menu.php
Created Jul 5, 2019
Simple wordpress megamenu
View function-menu.php
<?php
/*
* REGISTER NAVIATION MENUS
*************************************************************/
add_action( 'after_setup_theme', 'register_make_nav_menus' );
function register_make_nav_menus() {
register_nav_menus( array(
'header-menu' => 'Main Header Menu',
) );
}
@aaronsummers
aaronsummers / dynamic-post-filter.php
Created Jun 26, 2019
Dynamic post / custom post type filter using taxonomies, categories and tags.
View dynamic-post-filter.php
<?php
$post_type = 'posts';
$post_count = 6;
/**
* @var [$current_post_type_taxonomies] Get all the taxonomies registered in wordpress
* @var [$actual_taxonomies] Remove post_format from the taxonomies
* @var [$tax_terms_array] Create an empty array for the taxonomy terms, this later is used to populate the tax_query in the loop
*/
@aaronsummers
aaronsummers / make_plural.php
Created Jun 24, 2019
Simple plural function php
View make_plural.php
<?php
function plural( $string ) {
$last_letter = substr($string, -1); // Get the last letter of the taxonomy name
if ( $last_letter != 's' ) :
// If it ends in a "Y" replace that with "IES" otherwise add an "S"
$string = ( $last_letter == 'y' ) ? substr($string, 0, -1) . 'ies' : $string . 's';
endif;
return $string;
View List style base.scss
ol, ul {
li {
margin-bottom: 1em;
}
padding-left: 1.4em;
}
ol li {
list-style: decimal-leading-zero;
You can’t perform that action at this time.