Skip to content

Instantly share code, notes, and snippets.

@dannydover
dannydover / setup-django-with-poetry.md
Last active September 7, 2020 18:32
Set Up Clean Django Installation Using Poetry - Credit: https://proxyroot.com/django-poetry/

Set Up Directory Structure:

mkdir projectname

cd projectname

Set Up Poetry:

poetry init

Add Dependency:

poetry add django

<?php
/*
Plugin Name: Google Analytics Tracking Code MU-Plugin
Description: A must-use plugin that adds immutable Google Analytics tracking code.
*/
/* This plugin is used to ensure that Google Analytics is always present on the site (thus the use of a mu-plugin)
and to maintain the relationship between WordPress themes (design) and WordPress plugins (functionality) by keeping this
code out of the theme and in a plugin. */
@dannydover
dannydover / functions.php
Created September 2, 2019 20:37
WordPress - Fix Infinite redirect on homepage (when using subdomain)
<?php
// Fix for infitite redirect of homepage when using subdomain. Thanks to andrewtaylor-1
// https://wordpress.org/support/topic/45-causes-infinite-redirect-on-static-front-page/
function disable_front_page_redirect($redirect_url) {
if( is_front_page() ) {
$redirect_url = false;
}
return $redirect_url;
}
@dannydover
dannydover / .gitignore
Last active September 10, 2020 16:40 — forked from salcode/.gitignore
Wordpress Specific .gitignore File That Whitelists Themes & Plugins
# -----------------------------------------------------------------
# .gitignore for WordPress
# Original file from @salcode (https://gist.github.com/salcode/b515f520d3f8207ecd04/raw/.gitignore)
#
# From the root of your project run
# curl -O https://gist.github.com/dannydover/5c03aade4bdb58b61e8a0b56c2464c2a/raw/.gitignore
# to download this file
#
# By default all files are ignored. You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
@dannydover
dannydover / functions.php
Last active November 19, 2018 18:18
Show Featured Image in Wordpress RSS Feed - Credit: https://woorkup.com/show-featured-image-wordpress-rss-feed/
<?php
/* Add Featured Image to beginning of RSS Feed entries */
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'large', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
}
return $content;
}
@dannydover
dannydover / functions.php
Last active November 19, 2018 18:11
Replace Published date with Updated date within Wordpress (Divi Specific)
<?php
/* Show last updated date rather than first posted date */
function show_last_modified_date_blog( $the_date, $format ) {
if ( 'guides' === get_post_type() && 'U' !== $format ) { // Make sure the Unix timestamp is not being requested.
$the_time = get_post_time( 'His' );
$the_modified = get_post_modified_time( 'His' );
$last_modified = sprintf( __( 'Last Updated %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
@dannydover
dannydover / functions.php
Last active October 6, 2018 22:11
Google Analytics (gtag.js) - Tracking outbound clicks as GA events without using Google Tag Manager
// Google Analtics (gtag.js) - Tracking external clicks as events without GTM
function track_outbound_clicks_with_GA() { ?>
<script>
(function trackOutboundClicks() {
var hitCallbackHandler = function(url,win) {
if (win) {
window.open(url, win);
} else {
window.location.href = url;
@dannydover
dannydover / functions.php
Last active October 6, 2018 22:06
Add Google Analytics (gtag.js) Tracking to top of <head> in Wordpress via Theme functions.php
<?php
// Google Analytics Tracking Code Snippet
add_action( 'wp_head', 'google_analytics_tracking', 1 );
function google_analytics_tracking( $priority ) {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-X"></script>
<script>
@dannydover
dannydover / functions.php
Last active July 23, 2018 02:30
Wordpress Images srcset SSL compatibility with Cloudflare. More info and credit: https://aaronsilber.me/2016/03/26/fix-broken-mixed-content-wordpress-4-4-srcset-responsive-images/
// Add Wordpress Images srcset SSL compatibility with Cloudflare.
add_filter( 'wp_get_attachment_url', 'set_url_scheme' );
add_filter( 'wp_calculate_image_srcset', function($sources) {
$filtered_sources = array();
foreach($sources as $source_key=>$source) {
$source['url'] = str_replace('http://','https://', $source['url']);
$filtered_sources[$source_key] = $source;
}
return $filtered_sources;