Skip to content

Instantly share code, notes, and snippets.

View celticwebdesign's full-sized avatar

Darren Stevens celticwebdesign

View GitHub Profile
@celticwebdesign
celticwebdesign / WordPress Plugin - YouTube Channel Video Counts
Created October 27, 2017 13:57
A WordPress plugin to get all videos from a YouTube Channel, adds up all video view counts.
<?php
/*
Plugin Name: CWD YouTube Channel
Version: 0.1
Plugin URI: http://www.celticwebdesign.net
Description: Render YouTube video count
Author: Darren Stevens
Author URI: http://www.celticwebdesign.net
*/
<a class="share_facebook" href="#" data-url="enter url here">F</a>
$('a.share_facebook').click(function(e) {
e.preventDefault();
var $this = $(this);
<a class="share_linkedin" href="#" data-url="https://www.linkedin.com/shareArticle?mini=true&amp;url=Enter URL here&amp;title=enter title here&amp;summary=enter summary here&amp;source=">L</a>
$('a.share_linkedin').click(function(e) {
e.preventDefault();
var $this = $(this);
<a class="share_twitter" href="#" data-title="title: URL">T</a>
$('a.share_twitter').click(function(e) {
e.preventDefault();
var $this = $(this);
@celticwebdesign
celticwebdesign / WordPress - show page link is page is parent or child
Created September 20, 2017 15:59
If the page is a parent then show child page links, if the page does not page child pages, show pages links of parent.
http://wp-snppts.com/archive
@celticwebdesign
celticwebdesign / WordPress - Visual Composer
Created September 17, 2017 21:00
Working with Visual Composer, get the content of one page and show it on another page, includes inner page css.
<?php
if ( get_field('above_footer') ) {
$post_id = get_the_id();
} else {
$post_id = 41;
}
$vcM = Vc_Manager::getInstance();
$vc = $vcM->vc();
function get_all_categories($taxonomy) {
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
)
);
if ( $terms && ! is_wp_error( $terms ) ) :
// http://www.wpbeginner.com/wp-tutorials/how-to-limit-search-results-for-specific-post-types-in-wordpress/
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('recipes'));
$query->set('posts_per_page',10);
}
return $query;
// https://stackoverflow.com/questions/965235/how-can-i-truncate-a-string-to-the-first-20-words-in-php
function limit_text($text, $limit) {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}