Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Knight KnightAlex

  • Devon, United Kingdom
View GitHub Profile
@KnightAlex
KnightAlex / functions.php
Created Jun 5, 2020
Shortcode for blockquote source in WordPress
View functions.php
//blockquote source shortcode
function bs_quote_source_shortcode($atts, $content, $tag){
$output = '<span class="source">' . $content . '</span>';
return $output;
}
add_shortcode('source','bs_quote_source_shortcode');
@KnightAlex
KnightAlex / functions.php
Created Jun 3, 2020
Remove Storefront footer widget areas
View functions.php
//remove some widget areas
function lt_remove_some_widget_areas(){
// Unregister some of the TwentyTen sidebars
unregister_sidebar( 'footer-1' );
unregister_sidebar( 'footer-2' );
unregister_sidebar( 'footer-3' );
unregister_sidebar( 'footer-4' );
}
add_action( 'widgets_init', 'lt_remove_some_widget_areas', 11 );
View style.scss
ul {
list-style: none;
li::before {
content: "\2022"; /* Add content: \2022 is the CSS Code/unicode for a bullet */
color: red; /* Change the color */
font-weight: bold; /* If you want it to be bold */
display: inline-block; /* Needed to add space between the bullet and the text */
width: 20px; /* Also needed for space (tweak if needed) */
margin-left: -2px; /* Also needed for space (tweak if needed) */
}
@KnightAlex
KnightAlex / functions.php
Created Dec 11, 2018
Re-save comma separated list of values into a "multiple instances of this field" field. WPAI.
View functions.php
add_action( 'pmxi_saved_post', 'post_saved', 10, 1 );
function post_saved( $id ) {
$comma_values = get_post_meta($id, 'my_custom_field', true);
$explode_comma_values = explode( ',', $comma_values );
delete_post_meta( $id, 'my_custom_field', $comma_values ); //Clear custom field first
foreach($explode_comma_values as $v){
add_post_meta( $id, 'my_custom_field', $v );
}
}
@KnightAlex
KnightAlex / functions.php
Created Jun 14, 2018
ISBN 13 to 10 conversion, via shortcode
View functions.php
add_shortcode('isbn-13to10', 'ISBN13toISBN10_shortcode');
// Converts ISBN-13 to ISBN-10
// Leaves ISBN-10 numbers (or anything else not matching 13 consecutive numbers) alone
function ISBN13toISBN10_shortcode($atts) {
extract( shortcode_atts( array(
'isbn' => ''
), $atts ) );
if (preg_match('/^\d{3}(\d{9})\d$/', $isbn, $m)) {
$sequence = $m[1];
$sum = 0;
@KnightAlex
KnightAlex / 0_reuse_code.js
Created Jan 19, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@KnightAlex
KnightAlex / style.css
Created Apr 6, 2016
Device orientation media queries
View style.css
/* portrait */
@media screen and (orientation:portrait) {
/* portrait-specific styles */
}
/* landscape */
@media screen and (orientation:landscape) {
/* landscape-specific styles */
}
@KnightAlex
KnightAlex / style.css
Last active Oct 14, 2015
Font % resize trick
View style.css
html {
font-size: 62.5%;
}
body {
font: 1.6em/1.4 'Roboto', sans-serif;
}
@KnightAlex
KnightAlex / functions.php
Created Jul 22, 2015
Echo out SQL queries in WordPress
View functions.php
if ( !defined('SAVEQUERIES') && isset($_GET['debug']) && $_GET['debug'] == 'sql' )
define('SAVEQUERIES', true);
if ( !function_exists('dump') ) :
/**
* dump()
*
* @param mixed $in
* @return mixed $in
**/
@KnightAlex
KnightAlex / functions.php
Last active Aug 29, 2015
Add custom styles to the WordPress TinyMCE editor
View functions.php
/* add a a styleselect drop down menu on the second row of the buttons */
function wpb_mce_buttons_2($buttons) {
array_unshift($buttons, 'styleselect');
return $buttons;
}
add_filter('mce_buttons_2', 'wpb_mce_buttons_2');
/*