Skip to content

Instantly share code, notes, and snippets.

View marcwieland95's full-sized avatar

Marc Wieland marcwieland95

View GitHub Profile
@marcwieland95
marcwieland95 / functions.php
Created April 10, 2024 09:52
Load Legacy Script via WordPress for old browser (nomodule)
add_action('wp_enqueue_scripts', function() {
wp_register_script(
'scripts-legacy',
get_template_directory_uri() . '/build/scripts-legacy.js',
['jquery'],
getenv('GIT_COMMIT_SHORT_SHA'),
true
);
@marcwieland95
marcwieland95 / script.js
Created April 10, 2024 09:40
Prefetch sites on idle and prerender sites on hover
import { listen } from 'quicklink';
import ProbaClick from 'probaclick';
// Quicklink
window.addEventListener('load', () => {
listen({
ignores: [(uri) => uri.includes('wp-') || uri.includes('.pdf') || uri.includes('.zip')],
});
});
@marcwieland95
marcwieland95 / Admin.php
Last active January 9, 2023 03:49
Style ACF fields as deprecated
class Admin
{
public function __construct()
{
add_action('admin_enqueue_scripts', [$this, 'acfDeprecationStyles'], 10, 2);
}
public function acfDeprecationStyles()
{
echo '<style type="text/css">';
@marcwieland95
marcwieland95 / WpRestCache.php
Created September 15, 2022 09:47
Clear WP REST API Cache on certain interactions from WP Admin Panel
<?php
use WP_Rest_Cache_Plugin\Includes\Caching\Caching;
class WpRestCache
{
public function __construct()
{
add_filter('wp_rest_cache/allowed_endpoints', [$this, 'cacheEndpoints'], 10, 1);
add_filter('wp_rest_cache/determine_object_type', [$this, 'determinteObjectType'], 10, 4);
@marcwieland95
marcwieland95 / Oembed.php
Last active May 6, 2022 18:36
WordPress oEmbed handler to integrate video and audio players from SRG (including SRF, RSI, RTS and RTR)
wp_embed_register_handler('srg', '#https?:\/\/(?:www\.|player\.)?(srf|rsi|rts|rtr)\.ch\/.+(detail|video|audio).((?:.{8}-.{4}-.{4}-.{4}-.{12})|\d*)(?:.startTime=(\d*)|.*)#i', 'srgEmbedHandler');
function srgEmbedHandler($matches, $attr, $url, $rawattr)
{
return sprintf(
'<iframe width="560" height="315" src="https://%1$s.ch/play/embed?urn=urn:%1$s:%2$s:%3$s%4$s" allowfullscreen allow="encrypted-media"></iframe>',
esc_attr($matches[1]),
esc_attr($matches[2]) === 'audio' ? 'audio' : 'video',
esc_attr($matches[3]),
array_key_exists(4, $matches) ? esc_attr('&startTime=' . $matches[4]) : '',
@marcwieland95
marcwieland95 / gist:606351fffa50dd55e1beb05112992b1c
Last active January 25, 2021 08:59
Move folder to new repository and keeping history (inspired by https://gist.github.com/trongthanh/2779392)
git clone <repourl>/repo-1.git
cd repo-1
git remote rm origin # delete link to original repository to avoid any accidental remote changes
git filter-branch --subdirectory-filter dir-to-move -- --all # dir-to-move is being moved to another repo. This command goes through history and files, removing anything that is not in the folder. The content of this folder will be moved to root of the repo as a result.
git tag -d $(git tag -l) # remove all tags from the old repository - history should now be clean
git remote add master ../new-repo/ # add the link to the new repo
git push # the new repo has just the moved folder including the history inside
a {
position: relative;
display: inline-block;
font-size: 2em;
font-weight: 800;
color: royalblue;
overflow: hidden;
background: linear-gradient(to right, midnightblue, midnightblue 50%, royalblue 50%);
background-clip: text;
-webkit-background-clip: text;
<link rel="icon" href="/favicon.ico" /><!-- 32×32 -->
<link rel="icon" href="/icon.svg" type="image/svg+xml" sizes="any" />
<link rel="apple-touch-icon" href="/apple.png" /><!-- 180×180 -->
<link rel="manifest" href="/manifest.webmanifest" />
@marcwieland95
marcwieland95 / script.js
Created May 16, 2020 10:45
load Event Listener
function winLoad(callback) {
if (document.readyState === 'complete') {
callback();
} else {
window.addEventListener("load", callback);
}
}
winLoad(function() {
console.log('Window is loaded');
@marcwieland95
marcwieland95 / footer.php
Created January 3, 2019 19:54
Automatically updating copyright year - http://updateyourfooter.com/