Skip to content

Instantly share code, notes, and snippets.

@wpflames
wpflames / script.js
Created September 9, 2020 06:40
JavaScript add class / remove class 2
const menuBtn = document.querySelector('.menu-btn');
let menuOpen = false;
menuBtn.addEventListener('click', () => {
if(!menuOpen) {
menuBtn.classList.add('open');
menuOpen = true;
} else{
menuBtn.classList.remove('open');
menuOpen = false;
@wpflames
wpflames / script.js
Created September 9, 2020 06:47
JavaScript toggle to add “active” class
function toggle(){
var button = document.getElementById('btn-toggle');
button.classList.toggle('active');
}
@wpflames
wpflames / index.html
Created September 9, 2020 06:49
JavaScript toggle to add “active” class HTML
<button id=""btn-toggle" onclick="toggle()">Button</button>
@wpflames
wpflames / genesis-loop.php
Last active January 22, 2021 17:55
Genesis Loop for Custom Post Type with Pagination
<?php
// =========================================================================
// GENESIS LOOP FOR CUSTOM POST TYPE
// =========================================================================
function custom_loop_with_pagination() {?>
<article class="page type-page entry">
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
@wpflames
wpflames / functions.php
Created November 26, 2020 07:35
How to list Custom Post Type's Taxonomies
<?php
if( $terms = get_terms( array(
'taxonomy' => 'YOUR_TAXONOMY',
'orderby' => 'name'
) ) ) : ?>
<ul class="faq-filter">
<li><a href="">All</a></li>
<?php foreach ( $terms as $term ) : ?>
<li><a id="faq-filter-id-<?php echo $term->term_id; ?>" href=""><?php echo $term->name; ?></a></li>
<?php endforeach; ?>
@wpflames
wpflames / script.js
Created November 27, 2020 18:04
jQuery - Add class / remove class
jQuery('.YOUR_CLASS').on('click', function() {
jQuery('.YOUR_CLASS').removeClass('active');
jQuery(this).addClass('active');
});
@wpflames
wpflames / functions.php
Last active November 29, 2020 17:58
Enqueue script
<?php //don't copy the opening php tag
// =============================================================
// DEFINE CONSTANTS
// =============================================================
define('THEME', get_stylesheet_directory_uri());
// =============================================================
// ENQUEUE SCRIPTS
// =============================================================
@wpflames
wpflames / app.js
Created November 30, 2020 09:28
JavaScript addEventListener click
var btn = document.getElementById('button');
btn.addEventListener('click', loadText);
function loadText(){
console.log('button clicked');
}
@wpflames
wpflames / app.js
Created November 30, 2020 09:39
AJAX request for a TXT file
var btn = document.getElementById('button');
btn.addEventListener('click', loadText);
function loadText(){
//Create XHR Object
var xhr = new XMLHttpRequest();
//OPEN - type, url/file, async
@wpflames
wpflames / app.js
Created November 30, 2020 10:26
AJAX request for a TXT file - readystate
var btn = document.getElementById('button');
btn.addEventListener('click', loadText);
function loadText(){
//Create XHR Object
var xhr = new XMLHttpRequest();
//OPEN - type, url/file, async