Skip to content

Instantly share code, notes, and snippets.


Hugo - hnla hnla

  • London
View GitHub Profile
View Cache Busting - forcing that annoying cache to redownload our assets
// Cache busting dynamically
function get_file_last_mod($filename) {
$filename = dirname(__FILE__) . '/assets/css/' . $filename;
if( file_exists($filename) ){
$version = date ("M d Y H:i:s.", filemtime($filename));
// manual cache busting
$version = 'V1.0';
return $version;
hnla / BP Sitewide messages widget
Created Aug 16, 2013
Provides an implementation of BuddyPress sitewide message function in a widget for use in site sidebars, can replace BP legacy_theme wp_footer rendering.
View BP Sitewide messages widget
add_action('widgets_init', create_function('', 'return register_widget("HNLA_bp_sitewide_messages_Widget");') );
class HNLA_bp_sitewide_messages_Widget extends WP_Widget {
function __construct() {
'HNLA_bp_sitewide_messages_Widget', //the ID?
'HNLA BP Sitewide Messages', //the widget name
array( 'description' => __('Displays the BP admin \'all users\' sitewide messages', 'meson'), )
hnla / hnla BP login form widget
Created Aug 16, 2013
An implementation of the classic BuddyPress login form and logged in avatar,logout link provided as a widget.
View hnla BP login form widget
add_action('widgets_init', create_function('', 'return register_widget("HNLA_loggin_Widget");') );
class HNLA_loggin_Widget extends WP_Widget {
function __construct() {
'BP Login, Logout form',
array( 'description' => __('Displays the standard BP login form and logged in avatar, logout link', 'hnla'), )
hnla / BP User Account Links Shortcode
Last active Dec 18, 2015
This shortcode allows users to add BP user account links to posts or pages or widgets if widgets enabled for shortcode parsing. You can set the account screen to link to as single top level screen or child 'activity', 'activity/mentions' add text required to display for link, add text to display for the title attr on hover label, also you can se…
View BP User Account Links Shortcode
hnla / Shortcode get_post mini-loop
Created May 23, 2013
Simple mini post loop using on get_post and passing args for category id, qnt, and thumbs excerpts, intended for use in pages primarilly to render a light cat list of title links.
View Shortcode get_post mini-loop
* Shortcode get_post loop
* Shortcode displays loops for categories in posts or pages.
* It takes params for cat ID, qnt, show_thumbs, show_excerpt & height / width.
* [hnla_cat_loop cat_id='4' qnt='4' show_thumb=true show_excerpt=true, height='120', width='120' ]
* If showing thumbnails additional markup elements wrap the title and excerpt to allow positioning to right side of
* floated thumbnail.
hnla / BuddyPress username shortcode
Last active Dec 17, 2015
Needed a means of adding a user name to a WP page in a BuddyPress site the other day, easiest approach for this seemed to be a shortcode that the admin could add to the page.
View BuddyPress username shortcode
* Add BP username via a shortcode function
* Use in pages or posts?
* For no real reason one can pass a specific user id through
function display_username_in_posts($atts) {
$bp = buddypress();
"id" => '',
), $atts));
hnla / hnla-loggin-bp-sidebar-me
Last active Dec 17, 2015
A function to add the BuddyPress sidebar-me logged in username/avatar, plus site wide notice & a custom rendering of a users notifications displayed as a list e.g new @mentions, new private messages etc. On logout or logged out a login form is presented. The function can be placed in functions.php and the function call added to any sidebar file …
View hnla-loggin-bp-sidebar-me
function hnla_bp_login_bp_sidebar_me() {
* This function provides BP sidebar login form if logged out
* welcome message username & logout link if logged in,
* list of any new notification on your account,
* sitewide site notices if any posted by site admin.
* Add function to your function.php file
* call function in any sidebar file using:
hnla / WP-dropdown-style-dropin
Last active Dec 16, 2015
A simple set of rulesets to add dropdown styling for WP menu structures.
View WP-dropdown-style-dropin
* A basic dropdown set of styles for WP wp_nav_menu() / wp_pages_list()
* This dropin group of rulesets uses a top level selector nav#site-main which needs to be changed to suit or added to markup.
* There is a simple series of CSS Transitions to provide a little smoothness to the opening / closing of the menu and opacity * transitioned on the li elements.
* There are background colours added and obviously these are subjective and won't suit all themes so need changing
* There is a comlimentary JS snippet that just adds classes to hovered li elements and their parents, this is named in time * honoured manner as 'sfhover' it's real purpose used to be to provide support for IE but are also useful to provide xpath * navigation back up the li nodes and used here to add li backgrounds on all hovered elements parents. In addition the script * Adds a class 'has-child' to li elements having nested ul li children.
/* Configure main menu dropdowns */
nav#site-main ul li {