Skip to content

Instantly share code, notes, and snippets.

View celticwebdesign's full-sized avatar

Darren Stevens celticwebdesign

View GitHub Profile
@celticwebdesign
celticwebdesign / WordPress - Get All Categories
Created September 1, 2017 08:23
WordPress - Get All Categories
function get_all_categories($taxonomy) {
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
)
);
if ( $terms && ! is_wp_error( $terms ) ) :
@celticwebdesign
celticwebdesign / WordPress - Enqueue script on specific page template
Created August 18, 2017 08:36
WordPress - Enqueue script on specific page template
// https://wordpress.stackexchange.com/questions/61244/wp-enqueue-style-on-specific-page-templates
function my_enqueue_stuff() {
global $template;
$template_array = explode('/',$template);
if ( end($template_array) == 'single-recipes.php' ) {
wp_enqueue_script('jspdf', 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.debug.js', array(), '20170816', true );
// http://rawgit.com/MrRio/jsPDF/master/docs/
// A library to generate PDFs in client-side JavaScript.
@celticwebdesign
celticwebdesign / WordPress - import Fontawesome fonts
Created August 8, 2017 09:51
WordPress - import Fontawesome fonts
function bones_fonts() {
wp_enqueue_style('googleFonts', '//fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Nunito:300,300i,400,600,700');
}
add_action('wp_enqueue_scripts', 'bones_fonts');
Add to functions.php or separate plugin.
echo limit_text( get_field('village_finds_report'), 40, get_permalink( get_the_id() ) );
// originally taken from
// https://stackoverflow.com/questions/965235/how-can-i-truncate-a-string-to-the-first-20-words-in-php
// slightly adjusted to include a url.
function limit_text($text, $limit=40, $url='') {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
Using WordPress - Advance Custom Fields Pro
<?php
$rows_hfbir = get_field('homepage_full_browser_images_repeater');
if($rows_hfbir) {
@celticwebdesign
celticwebdesign / content-product.php
Last active April 3, 2024 12:12 — forked from croosen/content-product.php
WooCommerce - Display custom attributes on shop page - including attribute thumbnails
<?php
// this gist requires: http://candlestudio.net/woocommerce/plugins/button-variations/
// a fork of: https://gist.github.com/croosen/24a2845f91ce91a2819b
// WooCommerce - Display custom attributes on shop page - the official way ;-)
global $wc_ea_term_meta;
// Get the attributes
<?php
$local_folder = get_field('video_folder');
$path = "/var/sites/k/XXX.co.uk/public_html/Videos/top-video-folder/".$local_folder;
$files = scandir($path);
foreach ($files as &$value) {
if ($value != "." && $value != "..") {
@celticwebdesign
celticwebdesign / PHP - WordPress - JSON encode
Created March 24, 2017 13:52
PHP encoding an array or arrays into JSON for JS Slideshow plugin.
function get_pop_up($ID) {
$rows_fss = get_field('slideshow_repeater',$ID);
$output = "";
if($rows_fss) {
$output .= "<div id='inline1' style='display: none;'>";
// http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/
//
// Select a Restaurant
class eoc_widget_select_restaurant extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'eoc_widget_select_restaurant',
add_shortcode('shortcode_find_accommodation', 'shortcode_find_accommodation');
function shortcode_find_accommodation() {
$terms = get_terms( array(
'taxonomy' => 'towns-accommodation',
'hide_empty' => false,
) );
if ( $terms && ! is_wp_error( $terms ) ) :