Skip to content

Instantly share code, notes, and snippets.

View ScarletPonytail's full-sized avatar

ScarletPonytail ScarletPonytail

View GitHub Profile
@ScarletPonytail
ScarletPonytail / single.php
Created June 7, 2018 08:59
Wordpress - Preview markup on single.php via a template
// Get people preview template
if ( is_singular( 'sc_people' ) && is_preview() ) :
get_template_part( 'template-parts/people', 'preview' );
endif;
@ScarletPonytail
ScarletPonytail / stye.css
Last active June 6, 2018 15:24
CSS - Animated background gradient
.all {
overflow: hidden;
display: block;
position: absolute;
width: 100%;
height: 100%;
animation: bodygradient 45s infinite;
-webkit-animation: bodygradient 45s infinite;
-moz-animation: bodygradient 45s infinite;
border: 20px solid rgba(255, 255, 255, 0.5);
@ScarletPonytail
ScarletPonytail / script.js
Last active June 6, 2018 14:31
jQuery - If .class is visible viewport
jQuery( window ).load( function () {
jQuery.fn.isOnScreen = function() {
var win = jQuery( window );
var viewport = {
top: win.scrollTop(),
left: win.scrollLeft()
};
viewport.right = viewport.left + win.width();
@ScarletPonytail
ScarletPonytail / page.php
Last active June 1, 2018 10:10
PHP - How to check for a class
function the_thing() {
$classes = get_body_class();
if( in_array( 'the-class', $classes, true ) ) {
// Do a thing
}
}
// or
function the_thing() {
@ScarletPonytail
ScarletPonytail / author.php
Last active May 25, 2018 14:33
Wordpress - Have posts
<?php
$args = array(
'post_type' => 'your_custom_post_type',
'author' => get_current_user_id(),
);
$wp_posts = get_posts($args);
if (count($wp_posts)) {
@ScarletPonytail
ScarletPonytail / script.js
Last active May 9, 2018 09:50
jQuery - Use an appended dropdown to hide content using classes
// Loops through the tabs and if true, run function to create dropdown
$( '.tab-wrap > .panel' ).each(function( index, value ) {
if ( $( '.header-only', value ).length > 1 ) {
yearsfilter( value );
}
})
function yearsfilter( panel ) {
// Creates dropdown
$( panel ).prepend('<div class="contact-filter"><div class="sc-filtering"><select class="theyears filters-select"><option value="">Show All</option></select></div></div>');
@ScarletPonytail
ScarletPonytail / frontend.php
Created April 24, 2018 14:59
Wordpress - Wrap image with a link to the button
================================================================
Opening
================================================================
<?php // Check if the buttons should show
if ( 'yes' === $settings->cb_blk_one_show_btns ) :
// Run a foreach loop over every button from global options
if ( count( $settings->cb_blk_one_btns ) === 1 ) :
foreach ( $settings->cb_blk_one_btns as $key => $val ) :
@ScarletPonytail
ScarletPonytail / template-insights.php
Created April 18, 2018 10:05
WordPress - Define category order
$insightcats = get_categories( [
'orderby' => 'include',
'include' => array( 9, 6, 7, 8, 5 )
] );
@ScarletPonytail
ScarletPonytail / console.txt
Last active April 12, 2018 10:17
Git - Undo a commit
// https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Careful: git reset --hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. Be sure to stash any local changes you want to keep before running this command.
Assuming you are sitting on that commit, then this command will wack it...
git reset --hard HEAD~1
The HEAD~1 means the commit before head.
Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this:
@ScarletPonytail
ScarletPonytail / index.php
Created April 6, 2018 10:00
PHP - Bracket syntax inline if statement
<?php if ( has_term( 'quote', 'sc_insighttype' ) ) {
$insightquote = get_post_meta( get_the_ID(), 'mbsc-insight-quote', true );
?>
<div class="insight-box-quote">
<?php if ( substr( $insightquote, 0, 1 ) === '"' || utf8_decode( substr( $insightquote, 0, 1 ) ) === utf8_decode( '“' ) ) { ?>
<?php echo '<h3>' . esc_html( $insightquote ) . '</h3>'; ?>
<?php } else { ?>
<?php echo '<h3>' . '“' . esc_html( $insightquote ) . '”' . '</h3>'; ?>
<?php } ?>
</div>