Skip to content

Instantly share code, notes, and snippets.

Working from home

Laurence Bahiirwa bahiirwa

Working from home
View GitHub Profile
bahiirwa / Accessing WordPress Children, Grand children until 4 levels deep.
Created Oct 6, 2016
Accessing WordPress Children 4 levels deep. Please note in HTML I used boostrap. I also preserved the child page id for querying each level deep.
View Accessing WordPress Children, Grand children until 4 levels deep.
Add this to functions php file to Return parent page ID or child as else.
function get_top_parent_page_id() {
global $post;
if ($post->ancestors) {
return end($post->ancestors);
} else {
bahiirwa / Using function to limit the characters returned
Created Oct 6, 2016
Using function to limit the characters returned in WordPress
View Using function to limit the characters returned
I don't quite get your question but his worth a try, if I am understanding you. Add this function to your functions.php or a related file
function get_excerpt2($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, ""));
return $excerpt;
bahiirwa / wp-update-url.sql
Created Oct 11, 2016 — forked from jpederson/wp-update-url.sql
This sql file will update the URLs in all relevant WordPress tables when you move a site form one domain to another. Simply change the variables at the top to your URLs and execute it.
View wp-update-url.sql
SET @wp_url_old = '', @wp_url_new = '';
UPDATE wp_options SET option_value = replace( option_value, @wp_url_old, @wp_url_new )
WHERE option_value LIKE CONCAT( '%', @wp_url_old, '%' );
UPDATE wp_posts SET guid = replace( guid, @wp_url_old, @wp_url_new );
UPDATE wp_posts SET post_content = replace( post_content, @wp_url_old, @wp_url_new );
UPDATE wp_postmeta SET meta_value = replace( meta_value, @wp_url_old, @wp_url_new );
bahiirwa / functions.php
Created Oct 19, 2016 — forked from srikat/functions.php
Adding a cart icon with number of items and total cost in nav menu when using WooCommerce.
View functions.php
//* Make Font Awesome available
add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' );
function enqueue_font_awesome() {
wp_enqueue_style( 'font-awesome', '//' );
* Place a cart icon with number of items and total cost in the menu bar.
bahiirwa / gist:8d5de040e62ca72598260766643c570d
Created Oct 28, 2016 — forked from mikejolley/gist:6713608
WooCommerce Shipping Method Skeleton Plugin
View gist:8d5de040e62ca72598260766643c570d
Plugin Name: Your Shipping plugin
Plugin URI:
Description: Your shipping method plugin
Version: 1.0.0
Author: WooThemes
Author URI:
bahiirwa / woo-shipping-methods.php
Created Oct 29, 2016
Creating a woocommerce shipping method based on total number of cart items.
View woo-shipping-methods.php
function your_shipping_method_init() {
if ( ! class_exists( 'WC_Your_Shipping_Method' ) ) {
class WC_Your_Shipping_Method extends WC_Shipping_Method {
Constructor for your shipping class
public function __construct() {
bahiirwa / functions.php
Created Nov 1, 2016 — forked from WooForce/functions.php
Rearrange shipping methods
View functions.php
add_filter('woocommerce_package_rates', 'wf_sort_shipping_methods', 10, 2);
function wf_sort_shipping_methods($available_shipping_methods, $package)
// Arrange shipping methods as per your requirement
$sort_order = array(
'wf_shipping_ups' => array(),
'wf_shipping_usps' => array(),
'free_shipping' => array(),
'local_pickup' => array(),
bahiirwa / action.php
Created Nov 27, 2016 — forked from danielpataki/action.php
WordPress Emails
View action.php
function set_mail_html_content_type() {
return 'text/html';
add_action( 'publish_post', 'author_publish_notice', 10 ,2 );
function author_publish_notice( $ID, $post ) {
if( 'post' == $post->post_type ) {
bahiirwa /
Created Apr 12, 2017 — forked from fnichol/
Download a cacert.pem for RailsInstaller


There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?


The Ruby Way! (Fun)

bahiirwa / Default Taxonomy Term for CPT
Created Aug 5, 2017 — forked from mayeenulislam/Default Taxonomy Term for CPT
Make Default taxonomy term for Custom Post Type - WordPress
View Default Taxonomy Term for CPT
* Author: Michael Fields
* Source:
* Thanks a lot for the nice tweak
* Define default terms for custom taxonomies in WordPress 3.0.1