Skip to content

Instantly share code, notes, and snippets.

@ctlcltd
ctlcltd / wordpress_low-quality-image-placeholders_lqip.md
Last active June 22, 2023 20:08
How to easily generate low quality image placeholders (lqip) in WordPress

How to easily generate low quality image placeholders (lqip) in WordPress

I have made this function using the WP_Image_Editor class and I have filtered through the "wp_generate_attachment_metadata" hook. You can modify the "theme" namespace into function names with your theme name or in anyway you like.

Applying the filter directly to wp_generate_attachment_metadata the image placeholders are auto added into WordPress metadata, so when your add/modify/delete an image (or regenerate it via a plugin), it accomplishes to modify also to the image placeholders.

The use of the native theme support can prevent the generation of lqip or target specific image sizes to generate.

It contains an hook filter lqip_quality to modify the quality without have to modify the function.

@ctlcltd
ctlcltd / loop_trick_dailymotion.html
Last active February 12, 2018 15:20
Loop trick Dailymotion
<script type="text/javascript" src="https://api.dmcdn.net/all.js"></script>
<div id="player"></div>
<script type="text/javascript">
var DM_player = DM.player(document.getElementById('player'), {
video: 'x32llg2',
width: '100%',
height: '100%',
params: {
autoplay: true,
endscreenEnable: false,
@ctlcltd
ctlcltd / wp_gutenberg_columns_css_framework_classnames.js
Last active March 11, 2019 20:18
I'm looking for a proper method to add css framework classname in Gutenberg (WordPress 5) core/columns core/column blocks without overriding them. Suggestions, ideas, feedbacks will be appreciated.
window.theme_columns_inheritance = {initialized: false, grid: 12, last: -1, count: 0};
var initColumnsClassname = function(__) {
if ('theme_columns_inheritance' in window && ! theme_columns_inheritance.initialized) {
theme_columns_inheritance.initialized = true;
}
return __;
@ctlcltd
ctlcltd / _image-bg-dominance.md
Last active April 4, 2021 17:19
How to achieve the progressive loading of images with a background color in WordPress.

How to achieve the progressive loading of images with a background color in WordPress

To achieve the progressive loading of images, a background color can be used, which can be assigned before loading is performed and it will be shown during the loading phase of the web page. It could be an average of the image color, the predominant color, the same background color of the image, a background image or a color you like. This is an example of how to integrate it into an existing WordPress theme with filters. It is also possible to alter the IPTC metadata of the uploaded image and magically put a color value to the attachment metadata.

I used "wp_read_image_metadata" and "wp_generate_attachment_metadata" hooks to add a color value with the IPTC Instructions field and save a post metadata of the attachment.

/**
 * IPTC metadata - Instru