Skip to content

Instantly share code, notes, and snippets.

View johanguse's full-sized avatar
🏠
Working from home

Johan Guse johanguse

🏠
Working from home
View GitHub Profile
@johanguse
johanguse / function.php
Created October 19, 2023 13:07
Show the page file template name
add_filter( 'the_content', 'so_9405896_the_content_filter', 20, 1 );
function so_9405896_the_content_filter( $content )
{
if( is_admin() || !current_user_can( 'administrator' ) )
return $content;
global $template;
$the_templ = '<strong style="background-color: #CCC;padding:10px">TEMPLATE = '
. basename( $template ) . '</strong><br />';
@johanguse
johanguse / replace.py
Created September 14, 2023 02:35
Replace a domain in a big SQL file
import re
import os
import time
def replace_domain_in_large_sql(filename, old_domain, new_domain):
start_time = time.time()
temp_filename = filename + '.tmp'
count = 0
@johanguse
johanguse / nonce.php
Created July 18, 2023 14:27
Add nonce to script and styles on WordPress
add_action( 'template_redirect', function () {
ob_start( function ( $output ) {
$nonces = [];
$output = preg_replace_callback( '#<script.*?\>#', function ( $matches ) use ( &$nonces ) {
$nonce = wp_create_nonce( $matches[0] );
$nonces[] = $nonce;
@johanguse
johanguse / Hubspot Hubl Search with Suggestions.html
Last active June 11, 2023 14:27
Hubspot Hubl Search with Suggestions
<section class="bg-gray-001">
<div class="w-10/12 mx-auto grid gap-5 py-8">
<div class="hs-search">
<h2 class="mb-2 text-xl font-normal">Explore More</h2>
<div class="hs-search-field">
<div class="hs-search-field__bar">
<form id="hs-search-blog" action="/{{ site_settings.content_search_results_page_path }}" class="flex flex-col sm:flex-row">
<input type="text" class="hs-search-field__input p-4 sm:p-2 mb-2 sm:mb-0" name="term" autocomplete="off" aria-label="{{ "Search" }}" placeholder="{{ "Type to search" }}">
<input type="hidden" class="lg:pr-1" name="type" value="BLOG_POST">
<input type="hidden" name="pathPrefix" value="info">
@johanguse
johanguse / Hubspot Blog Pagination Tailwind.html
Created June 9, 2023 17:38
Hubspot Blog Pagination TailwindCSS
{% if contents.total_page_count > 1 %}
<div class="blog-pagination clearfix flex items-center space-x-1">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
{% if last_page_num %}
@johanguse
johanguse / Hubspot Blog Numbered Pagination.html
Last active June 9, 2023 17:37
Hubspot Blog Numbered Pagination
{% if contents.total_page_count > 1 %}
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
<div class="blog-pagination-left">
@johanguse
johanguse / functions.php
Last active December 22, 2021 17:25
Add width and height SVG upload on WordPress
/* ------------------------------------------------------------------------------- */
/* Add media data (width and height) to SVG upload
/* https://wordpress.stackexchange.com/a/256701/164915
/* Alternative: https://wordpress.org/plugins/enable-svg-uploads/
/* ------------------------------------------------------------------------------- */
function svg_meta_data($data, $id){
$attachment = get_post($id); // Filter makes sure that the post is an attachment
$mime_type = $attachment->post_mime_type; // The attachment mime_type
@johanguse
johanguse / image_sizes.php
Last active March 21, 2024 01:27
List all image sizes from WordPress including custom sizes
<?php
$image_sizes = wp_get_additional_image_sizes();
foreach ( $image_sizes as $key => $image_size ) {
echo "{$key} ({$image_size['width']} x {$image_size['height']})";
}
?>
@johanguse
johanguse / main.dart
Created March 20, 2020 22:03 — forked from vincevargadev/main.dart
switching theme without any library.
void main() {
runApp(_SwitchingThemeApp());
}
/// Properties that help me keep track of the example being run.
bool _useMaterial = false;
class _SwitchingThemeApp extends StatefulWidget {
@override
_SwitchingThemeAppState createState() => _SwitchingThemeAppState();
@johanguse
johanguse / gist:84c2d34a0d684a9ac369befbeb7147eb
Created September 14, 2019 14:29
A problem occurred evaluating project ':app'.
* Error running Gradle:
ProcessException: Process "complete_flutter_ecommerce-master\android\gradlew.bat" exited abnormally:
FAILURE: Build failed with an exception.
* Where:
Build file 'complete_flutter_ecommerce-master\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.