WordPress add to menu on the fly

add_filter( ‘wp_nav_menu_items’, ‘your_custom_menu_item’, 10, 2 ); function your_custom_menu_item ( $items, $args ) { //if (is_front_page()) { $items .= ‘<li>Show whatever</li>’; }else{ $items .= ‘<li>Show something else</li>’; } if ( is_page( array( ‘meet-the-group’, ‘contact-us’ ) ) || is_front_page()) { // either in about us, or contact, or management page is in view //$items .= ‘<li>Show whatever</li>’; […]

Read More

Smooth scroll to the top of the current page

Smooth scroll to the top of the current page const scrollToTop = () => { const c = document.documentElement.scrollTop || document.body.scrollTop; if (c > 0) { window.requestAnimationFrame(scrollToTop); window.scrollTo(0, c – c / 8); } }; scrollToTop();

Read More

Prevent Image Hotlinking with .htaccess

replace any incoming image request with my logo: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https://davidwalsh.name/.*$ [NC] RewriteRule .*.(png|gif|jpe?g)$ [F,NC] </IfModule>

Read More

DOM and Vanilla JS

Ariel Jakubowski DOM tree structure Using JavaScript to Manipulate the DOM Accessing DOM Elements The query selector finds the first element or node that matches a specified parameter. The most common ways a query selector is used are to access elements of a certain type, elements with a certain id, and elements with a certain […]

Read More

Prevent JavaScript Hotlinking with .htaccess

RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https://davidwalsh.name/.*$ [NC] RewriteRule \.(js)$ http://davidwalsh.name/hotlink.js [R,L] article hotlink.js file whose contents are a bit devious: window.location = ‘https://davidwalsh.name/’;

Read More

Prevent Image Hotlinking with .htaccess

replace any incoming image request with my logo: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https://davidwalsh.name/.*$ [NC] RewriteRule .*.(png|gif|jpe?g)$ [F,NC] </IfModule> article

Read More