Skip to content

Instantly share code, notes, and snippets.

View muks999's full-sized avatar

Muks999 muks999

View GitHub Profile
@atelierbram
atelierbram / wp-single-post-nav.php
Created September 9, 2018 15:35
WordPress Single Post Nav
<?php
if ( ! function_exists( 'mytheme_post_nav' ) ) :
/**
* Display navigation to next/previous post when applicable.
*
* @return void
*/
function mytheme_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
@atelierbram
atelierbram / querySelectorAll_Looping.js
Created November 14, 2018 20:07
A common need when writing vanilla JavaScript is to find a selection of elements in the DOM and loop over them. For example, finding instances of a button and attaching a click handler to them.
let buttons = document.querySelectorAll("button");
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
// http://kangax.github.io/compat-table/es6/#for..of_loops
for (const button of buttons) {
button.addEventListener('click', () => {
console.log("for of worked");
});
}
@atelierbram
atelierbram / wp-img-data-src-function.php
Last active September 5, 2021 13:06
Set data-src attribute in a function for lazy-loading of image (WordPress)
function rchv_projects_link() { ?>
<a class="grid_item-link gallery_item-link" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
<?php $imgPlaceholder = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk2A8AAMUAwUPJ2C4AAAAASUVORK5CYII="; ?>
<figure class="grid_item-figure gallery_item-figure">
<?php if( !empty(get_the_post_thumbnail()) ) {
the_post_thumbnail( 'post-thumbnail', array(
'alt' => the_title_attribute( array(
'echo' => false,
) ),
'src' => $imgPlaceholder,