Skip to content

Instantly share code, notes, and snippets.

@besimhu
besimhu / Breadcrumbs.php
Last active August 29, 2015 14:17
Basic breadcrumbs
<?php
function the_breadcrumb() {
global $post;
$blog = '<li><a href="'.esc_url( home_url() ).'/blog/" ?>Blog</a></li>';
echo '<div class="breadcrumbs-wrap">';
echo '<ul class="breadcrumbs">';
if (is_category() ) {
echo '<li>';
the_category('');
@besimhu
besimhu / Sub navigation on children and grand children pages.php
Last active August 29, 2015 14:17
Generate navigation based off parent, no matter if you are viewing children or grand children pages.
<nav class="sub-menu-wrap">
<ul class="sub-menu">
<?php
$children = wp_list_pages('depth=1&title_li=&child_of='.$post->ID.'&echo=0');
$current_page = wp_list_pages('title_li=&include='.$post->ID.'&echo=0');
$grandparent=0;
if($post->post_parent):
$parent = wp_list_pages('title_li=&include='.$post->post_parent.'&echo=0');
$siblings = wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&exclude='.$post->ID.'&echo=0');
@besimhu
besimhu / Sub-menu automation of interior menus.php
Last active August 29, 2015 14:17
It takes the main navigation and if there are any submenu items corresponding with the page, it will generate the navigation.
<?php
function submenu($menu, $returnParent = false) {
global $post;
$menu_items = wp_get_nav_menu_items($menu);
$menu_childs = array();
$menu_IDs = array();
$parent_item = 0;
@besimhu
besimhu / Header hide on scroll.js
Last active August 29, 2015 14:17
Hides header when you scroll down and shows when you scroll back up. The animation is handled through CSS. You can simply use a transform to move the navigation off screen.
function headerHide() {
// Hide Header on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('.header-global').outerHeight();
$(window).scroll(function(event){
didScroll = true;
@besimhu
besimhu / Pagination
Created March 15, 2015 15:02
You don't need a pagination plugin to handle pagination.
/**
* Wordpress Pagination
* http://codex.wordpress.org/Function_Reference/paginate_links
*/
<div class="pagination-wrap">
<?php
// pagination
global $wp_query;
$big = 999999999; // need an unlikely integer
@besimhu
besimhu / Smooth Scroll.js
Last active August 29, 2015 14:17
Smooth scroll any hashtag link to their ID.
// Smooth scroll to content
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
var targetH = $(this.hash),
target = targetH.length ? targetH : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 60
@besimhu
besimhu / Open all external links in new window.js
Last active August 29, 2015 14:17
Open all external links in a new window.
@besimhu
besimhu / Hide navigation on scroll + close navigation if clicked outside.js
Last active August 29, 2015 14:17
Toggle navigation, hide navigation on scroll, and close navigation if clicked outside of navigation.
module.exports = function() {
require('./setupMqSync')();
var $root = $('body'),
$header = $root.find('.main-header'),
$nav = $root.find('.nav-primary'),
$menu_toggle = $header.find('.menu-trigger'),
$active_class = 'nav-open',
prevent_default = function(e) {
@besimhu
besimhu / Add to Google and iCal.js
Last active August 29, 2015 14:17
Allow visitors to save/download events to their iCal or Google Calendar. The ical.php needs to go into your functions folder, and be pulled in. Included are sample styles, markup, ACF field option export, + variable pulling. Not all options will carry across to iCal.
module.exports = function() {
function sendInformation(){
var months = [
'01',
'02',
'03',
'04',
'05',
'06',
@besimhu
besimhu / Add <figure> and remove <p> tags from images..php
Created March 15, 2015 15:56
Remove paragraph tags around photos and instead add <figure> tag
// Remove paragraph tags around photos and instead add <figure> tag
function img_unautop($pee) {
$pee = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<figure class="post-img">$1</figure>', $pee);
return $pee;
}
add_filter( 'the_content', 'img_unautop', 30 );