Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View KnightAlex's full-sized avatar

Alex Knight KnightAlex

  • Devon, United Kingdom
View GitHub Profile
//unset Storefront templates
function theme_name_disable_page_template($post_templates, $theme, $post, $post_type)
{
unset($post_templates['template-fullwidth.php']);
unset($post_templates['template-homepage.php']);
return $post_templates;
}
add_filter('theme_templates', 'theme_name_disable_page_template', 10, 4);
@KnightAlex
KnightAlex / convert-string-to-slug.php
Last active May 9, 2023 12:38
Convert string to slug and replace special characters
//convert string to a slug
function get_slug_from_string($atts, $content = '')
{
extract(shortcode_atts(array(
'text' => ''
), $atts));
$slug = strtolower($text);
$slug = str_replace(' ', '-', $slug);
// replace special chars
@KnightAlex
KnightAlex / functions.php
Created June 5, 2020 14:55
Shortcode for blockquote source in WordPress
//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 June 3, 2020 14:23
Remove Storefront footer widget areas
//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 );
@KnightAlex
KnightAlex / style.scss
Created February 8, 2019 11:10
Bullet colour
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 December 11, 2018 14:38
Re-save comma separated list of values into a "multiple instances of this field" field. WPAI.
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
Last active November 28, 2023 10:14
ISBN 13 to 10 conversion, via shortcode
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 January 19, 2017 14:04
Here are some things you can do with Gists in GistBox.
// 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 April 6, 2016 08:32
Device orientation media queries
/* portrait */
@media screen and (orientation:portrait) {
/* portrait-specific styles */
}
/* landscape */
@media screen and (orientation:landscape) {
/* landscape-specific styles */
}
@KnightAlex
KnightAlex / style.css
Last active October 14, 2015 13:43
Font % resize trick
html {
font-size: 62.5%;
}
body {
font: 1.6em/1.4 'Roboto', sans-serif;
}