Skip to content

Instantly share code, notes, and snippets.

View mwender's full-sized avatar
👨‍💻

Michael Wender mwender

👨‍💻
View GitHub Profile
@mwender
mwender / trending-posts-shortcode.php
Last active April 18, 2024 13:40
[WordPress Elementor Trending Posts Shortcode] In conjunction with the Post Views Counter plugin, the following provides a "trending_posts" shortcode for use in displaying an Elementor Loop Template #elementor #wordpress
@mwender
mwender / impbcopy.m
Last active April 15, 2024 03:20
Command line copy an image file to the clipboard in Mac OS X. See first comment for install instructions.
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
if([path isEqualToString:@"-"])
{
// http://caiustheory.com/read-standard-input-using-objective-c
@mwender
mwender / uber-log.php
Last active April 2, 2024 16:55
uber_log() - Enhanced logging. Add this to your project and use `tail -f /path/to/your/log.txt` for debugging.
<?php
/**
* Enhanced logging.
*
* @param string $message The log message
*/
if( ! function_exists( 'uber_log' ) ){
function uber_log( $message = null ){
static $counter = 1;
@mwender
mwender / hidetext.js
Last active April 2, 2024 16:55
hidetext.js - A jQuery based function for showing long blocks of text as an excerpt with a "Read more..." link.
(function($){
function hideText( textselector, strlen, moretext ){
strlen = typeof strlen !== 'undefined' ? strlen : 100;
moretext = typeof moretext !== 'undefined' ? moretext : 'Read More';
var sections = $( textselector );
for(var i = 0; i < sections.length; i++ ){
console.log( sections[i] );
var textToHide = $( sections[i] ).html();
var textToCheck = $( sections[i] ).text().substring(strlen);
@mwender
mwender / optimize-video-ffmpeg.sh
Created January 19, 2024 22:33
[Optimize video files with ffmpeg] One liners for optimizing video files from your command line. #cli
# Reduce the filesize of your .mov and convert to .mp4
#
$ ffmpeg -i input.mov -vcodec h264 output.mp4
# Adjust the resolution of your .mov and convert to .mp4
#
# - The following sets the width to 1280px with the
# height adjusting appropriately.
# - scale={$width}:{$height} - Specify one value and set
# the other to -1 to scale proportionately
@mwender
mwender / email-obfuscater.js
Last active January 18, 2024 16:42
[JS Email Obfuscater] Simple JavaScript to obfuscate "mailto" links.
/**
* Obfuscates email addresses in 'mailto' links to protect them from spam bots.
*
* This function first selects all anchor elements (<a>) in the document that have a 'href' attribute
* starting with 'mailto:'. For each of these mailto links, it retrieves the email address,
* obfuscates it, and then modifies the link's 'href' attribute to use a JavaScript code snippet
* for redirection. This obfuscation involves converting each character of the email address
* into its corresponding character code, joined by dots. Additionally, a click event listener
* is added to each link to handle the redirection in a user-friendly manner. When a user
* clicks on the obfuscated link, the browser redirects them to the actual 'mailto' link,
@mwender
mwender / link-elementor-pro-gallery-images.js
Last active January 17, 2024 19:49
[Elementor Pro Linked Gallery Images] Simple JS to add links to your Elementor Pro gallery images #elementor
@mwender
mwender / README.md
Last active January 17, 2024 18:53
[ACF Unsafe Content Shortcode] Provides "acf_field_unsafe" for echoing ACF field content that hasn't been run through wp_kses_post(). #wordpress #shortcode #acf

The [acf_field_unsafe/] Shortcode

On January 16, 2024, the ACF 6.2.5 security release fixed a security issue whereby the output of the [acf field="[...]"/] shortcode has its content run through wp_kses(). This removes all <script> and <iframe> tags. However, there are still situations where you may need to echo these tags when you have a site where you're confident you can trust every user on your site with contributor or higher access. Hence, this shortcode allows you to do this.

Shortcode Documentation

Retrieves the value of a specified Advanced Custom Field (ACF) based on given attributes.

This function is designed to be used as a shortcode handler for retrieving ACF field values. 
@mwender
mwender / close-tabs-on-mobile.js
Last active January 17, 2024 17:28
Loads Elementor's tab widget on mobile with all tabs collapsed. #elementor
let intViewportWidth = window.innerWidth;
console.log('🔔 intViewportWidth = ', intViewportWidth );
const activeClass = 'ele-active';
const mobileBreakpoint = '767'; // Our breakpoint ensures this code only runs on small screens.
const mobileTabButtons = document.querySelectorAll('.elementor-tab-mobile-title');
if( intViewportWidth <= mobileBreakpoint ){
/**
* Click handling for Tab buttons.
@mwender
mwender / replace-hamburger-icon-with-text.css
Last active January 17, 2024 17:27
Use the following CSS to replace the Elementor Nav Widget's mobile dropdown hamburger icon with the word "Menu". #elementor
/* Use "Menu" for mobile menu */
selector .elementor-menu-toggle:not(.elementor-active) .elementor-menu-toggle__icon--open.eicon-menu-bar{
display: flex;
padding: 6px;
}
selector .elementor-menu-toggle:not(.elementor-active) .elementor-menu-toggle__icon--open.eicon-menu-bar:before{
content: 'Menu';
font-family: Roboto;
font-size: 18px;
}