Skip to content

Instantly share code, notes, and snippets.

@FreshLondon
FreshLondon / custom-menu.php
Last active January 13, 2019 10:41 — forked from nielslange/functions.php
List root and sub categories including their published posts
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu nav-menu" aria-expanded="false">
<?php
$root_cat_args = array('taxonomy' => 'products-category', 'hide_empty' => false, 'parent' => 0);
$root_categories = get_categories($root_cat_args);
foreach ($root_categories as $category) {
// Print all root category title
printf('<li><span>%s</span><ul class="depth-one">', $category->slug);
//debug($category);
@FreshLondon
FreshLondon / jquery-footer.js
Last active January 25, 2019 14:59
WordPress jQuery conflict mode - footer
@FreshLondon
FreshLondon / jquery-header.js
Created January 25, 2019 14:59
WordPress jQuery conflict mode - header
jQuery(document).ready(function( $ ) {
// $ Works! You can test it with next line if you like
// console.log($);
});
@FreshLondon
FreshLondon / simple-debugging.php
Created January 26, 2019 06:46
Display the contents of a $something
/**
* DEBUGGING
*/
function debug($data) {
print('<pre>');
print_r($data);
print('</pre>');
}
@FreshLondon
FreshLondon / debug-me.php
Last active January 26, 2019 06:59
using simple debugging in PHP
<?php
$images = get_field('image');
// we want to see whats inside, so we can instead use:
$images = get_field('image');
debug($images);
?>
@FreshLondon
FreshLondon / wp-enqueue-script-and-styles.php
Last active January 26, 2019 07:34
WordPress enqueue scripts and styles
<?php
// Enqueue scripts
wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false );
// Enqueue styles
wp_enqueue_style( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, string $media = 'all' );
<?php
/**
* ENQUEUE SCRIPTS AND STYLES
*/
function freshlondon_adding_scripts() {
wp_enqueue_script('my_amazing_jquery', get_template_directory_uri() . '/assets/js/jquery.min.js', false, '3.1.0', false);
wp_enqueue_script('my_amazing_slider', get_template_directory_uri() . '/assets/js/owl.carousel.js', array('my_amazing_jquery'), '1.0', false);
wp_enqueue_style('extra-fonts', get_template_directory_uri() . '/fonts/fonts.css', false, time(), 'screen');
wp_enqueue_style('fa-icons', 'https://use.fontawesome.com/releases/v5.6.3/css/all.css', false, '5.6.3', 'screen');
@FreshLondon
FreshLondon / header.html
Last active January 26, 2019 11:32
WordPress loaded scripts and styles
<!-- default theme stylesheet is loading here -->
<link rel='stylesheet' id='freshlondon-style-css' href='https://freshlondon.biz/wp-content/themes/freshlondon/style.css?ver=5.0.3' type='text/css' media='all' />
<!-- ..and then the stylesheets that had style.css as their dependancy-->
<link rel='stylesheet' id='extra-fonts-css' href='https://freshlondon.biz/wp-content/themes/freshlondon/fonts/fonts.css?ver=1548499243' type='text/css' media='screen' />
<!-- Did you notice the line above where it said 'fonts.css?ver=1548499243' <- this is the result of the PHP time() function we used! -->
<link rel='stylesheet' id='gist-styles-css' href='https://freshlondon.biz/wp-content/themes/freshlondon/assets/stylesheets/tomorrow-night.css?ver=5.0.3' type='text/css' media='screen' />
<link rel='stylesheet' id='owl-carousel-css' href='https://freshlondon.biz/wp-content/themes/freshlondon/assets/stylesheets/owl.carousel.min.css?ver=5.0.3' type='text/css' media='screen' />
<link rel='stylesheet' id='owl-carousel-theme-cs
@FreshLondon
FreshLondon / temmplate-frontpage.php
Created January 28, 2019 10:43
Template code for the top of the custom template in WordPress
<?php
/* Template Name: Fullwidth
* @package THEME_SLUG_HERE
*/
get_header();
@FreshLondon
FreshLondon / show-wp-image-sizes.php
Created March 4, 2019 18:23
Shows additional image sizes on WordPress
<?
global $_wp_additional_image_sizes;
print '<pre>';
print_r( $_wp_additional_image_sizes );
print '</pre>';
?>