Skip to content

Instantly share code, notes, and snippets.

View celticwebdesign's full-sized avatar

Darren Stevens celticwebdesign

View GitHub Profile
Using WordPress - Advance Custom Fields Pro
<?php
$rows_hfbir = get_field('homepage_full_browser_images_repeater');
if($rows_hfbir) {
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]) . '...';
@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.
@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 - 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 ) ) :
// 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;
}
// 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;
function get_all_categories($taxonomy) {
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
)
);
if ( $terms && ! is_wp_error( $terms ) ) :
@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();
http://wp-snppts.com/archive