Skip to content

Instantly share code, notes, and snippets.

View scottnunemacher's full-sized avatar
😁
Doing the things

Scott Nunemacher scottnunemacher

😁
Doing the things
View GitHub Profile
@scottnunemacher
scottnunemacher / wordpress-display-post-category-link.php
Created August 29, 2023 19:18
Wordpress - Display Loop's Post Category Link - Ex: display category link for an article
<?php
//Note Wordpress only uses the first category applied to a post.
$category = get_the_category();
if (!empty($category)) {
echo 'Category: <a class="post-category" href="' . esc_url(get_category_link($category[0]->term_id)) . '">' . esc_html($category[0]->name) . '</a>';
}
@scottnunemacher
scottnunemacher / wordpress-display-post-tag-links.php
Created August 28, 2023 22:50
Wordpress - Display Loop's Post Tag Links - Ex: display tag links for an article
<?php
// Will output links displayed like:
// Tags: Article Tag | Other Article Tag | Another Article Tag
$post_tags = get_the_tags();
$separator = ' | ';
$output = '';
if (!empty($post_tags)) {
echo "Tags: ";
@scottnunemacher
scottnunemacher / find-years-from-start-date.php
Created March 10, 2023 18:56
PHP - Find Years From Start Date
<?php
$startDate = new DateTime("1976-04-30");
$today = new DateTime('Y');
$interval = $startDate->diff($today);
echo $interval->y . " YEARS";
?>
@scottnunemacher
scottnunemacher / digitalocean-create-sudo-sftp-ssh-user.md
Created March 6, 2023 16:04
DigitalOcean Create sudo SFTP/SSH user

DigitalOcean Create sudo SFTP/SSH user

WARNING Create a snapshot before doing any changes!!!

Example new user data:

  • Username: exampleuser
  • Password: examplepassword
  • Home: /home/exampleuser/
  • IP: exa.mp.le.ip
@scottnunemacher
scottnunemacher / get-parent-directory.sh
Created January 31, 2023 23:13
Getting the parent of a directory from bash variable
#!/usr/bin/env bash
# From: https://stackoverflow.com/a/42956288
# example: dir=/home/smith/Desktop/Test
parentdir=$(builtin cd $dir; pwd)
@scottnunemacher
scottnunemacher / highlight-words-on-search.js
Created January 26, 2023 16:10
JS - Highlight all matches to search input on Enter.
// From: https://codingartistweb.com/2021/06/highlight-searched-text-with-javascript/
function search() {
// Use the id of the input ex: text-to-search
let textToSearch = document.getElementById("text-to-search").value;
// Use the id of the source to be searched ex: paragraph
let paragraph = document.getElementById("paragraph");
// Characters in search input to be escaped: [.*+?^${}()|[\]\\]
textToSearch = textToSearch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
let pattern = new RegExp(`${textToSearch}`, "gi");
@scottnunemacher
scottnunemacher / ssh-keygen-notes.sh
Last active January 5, 2023 17:56
ssh-keygen notes
# ssh-keygen for ed25519
ssh-keygen -a 100 -t ed25519 -f "/ABSOLUTE/PATH/TO/.ssh/PROFILE_SAASPROVIDER_ed25519" -C "PROFILE_SAASPROVIDER_ed25519"
# ssh-keygen for rsa 4096
ssh-keygen -b 4096 -t rsa -f "/ABSOLUTE/PATH/TO/.ssh/PROFILE_SAASPROVIDER_rsa" -C "PROFILE_SAASPROVIDER_rsa"
@scottnunemacher
scottnunemacher / find-recursively-and-cp-to-flat.sh
Last active January 5, 2023 17:56
Find recursively all files of extension and cp to flat directory
find . -name "*.pdf" -type file -exec cp {} /path/to/directory \;
@scottnunemacher
scottnunemacher / get-post-slug.php
Created October 13, 2022 19:09
WP Get Post Slug
<?php
$slug = get_post_field( 'post_name', get_post() );
echo $slug;
?>
@scottnunemacher
scottnunemacher / custom-search-results-subheading.php
Last active March 6, 2023 16:09
Custom Search Results Subheading
<?php
// Custom Search Results Subheading
add_filter( 'custom_search_results_subheading', function( $subheading ) {
if ( is_search() ) {
global $wp_query;
$posts_per_page = $wp_query->query_vars['posts_per_page'];
$posts_found = $wp_query->found_posts;
if ( $posts_found ) {
$subheading = sprintf(
esc_html__( 'Displaying results 1-%1$s out of %2$s for %3$s', 'total' ),