Skip to content

Instantly share code, notes, and snippets.

View lunule's full-sized avatar

lunule lunule

  • Vigilante One
  • Brno
View GitHub Profile
@lunule
lunule / wp--remove-patterns-from-appearance.php
Created January 25, 2025 23:08
[WordPress - Remove 'Patterns' from the Appearance Submenu] #fse #gutenberg #wp #patterns #appearance
<?php
/**
* Remove "Patterns" menu item from the "Appearance" submenu
*/
add_action('admin_menu', function() {
remove_submenu_page('themes.php', 'site-editor.php?path=/patterns');
});
@lunule
lunule / css--custom-select2-styles.js
Created December 29, 2024 07:28
[Select2 - Customize Select2 Styles] #select2 #custom #customize #styles #styling
jQuery(document).ready(function($){
if ( $('.map-slider-component').length ) {
$('.map-slider-component .select-city').select2({
width: '100%',
minimumResultsForSearch: Infinity // hide the search box
});
// Custom class provision upon select2 events
@lunule
lunule / wp--attach-template-to-cpt-posts.php
Created December 27, 2024 20:29
[WordPress - Programmatically Assign Page Template to CPT Posts] #wp #core #cpt #custom #post #types #page #templates
/**
* Attaches the specified template to the posts of the identified post type.
*
* @params $post_type The name of the post type to attach the template to.
* @params $template_path The template's filename (assumes .php' is specified)
*
* @returns empty array if the post type does not have posts; otherwise,
* the post id array of the updated posts.
*/
function attach_template_to_post_type( $post_type, $template_file_name ) {
@lunule
lunule / wp--get-page-by-title-goes-wp-query.php
Created December 22, 2024 20:59
[WordPress - `get_page_by_title()` deprecated => Use `WP_Query`] #wp_query #wp #core #get_page_by_title #get #page #by #title https://make.wordpress.org/core/2023/03/06/get_page_by_title-deprecated/
<?php
// Option 1: Use `WP_Query`
$query = new WP_Query(
array(
'post_type' => 'page',
'title' => 'Sample Page',
'post_status' => 'all',
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
@lunule
lunule / wp--log-to-error-log.php
Created December 22, 2024 14:20
[WordPress - Log to error.log] #wp #core #error #debug #log
<?php
if (!function_exists('write_log')) {
function write_log($log) {
if (true === WP_DEBUG) {
if (is_array($log) || is_object($log)) {
error_log(print_r($log, true));
} else {
error_log($log);
}
@lunule
lunule / wp--elementor--if-widget-loaded.php
Last active August 24, 2024 08:18
[WordPress - Elementor | Check if specific Elementor widget is loaded/used] #wp #elementor #widget #shortcode
<?php
global $post;
if ( is_a($post, 'WP_Post') ) :
$post_id = $post->ID;
$elementor_data = get_post_meta($post_id, '_elementor_controls_usage', true);
$has_fl_map = array_key_exists('fl-map', $elementor_data);
@lunule
lunule / js--mobile-checkers.js
Last active August 24, 2024 08:11
[JavaScript - Mobile Checkers] #collection #js #mobile #os
/**
* VERSION 1 - DEVICE-SPECIFIC + GLOBAL
* -----------------------------------------------------------------------------------------------------
*/
const checkIphone = () => {
const u = navigator.userAgent
return !!u.match(/iPhone/i)
},
checkAndroid = () => {
@lunule
lunule / php--mime-types.php
Last active July 24, 2024 05:50 — forked from plasticbrain/gist:3887245
PHP: mime types (array format)
<?php
$mime_types = array(
'.3dm' => 'x-world/x-3dmf',
'.3dmf' => 'x-world/x-3dmf',
'.a' => 'application/octet-stream',
'.aab' => 'application/x-authorware-bin',
'.aam' => 'application/x-authorware-map',
'.aas' => 'application/x-authorware-seg',
'.abc' => 'text/vnd.abc',
'.acgi' => 'text/html',
@lunule
lunule / highlight-js--basic-setup.css
Created June 9, 2024 00:16
[Highlight.js - Basic Setup] #highlight-js #syntax-highlighter
/* Copy Button plugin
------------------------------------------------------------------------------------------------
@here https://github.com/arronhunt/highlightjs-copy/styles/highlightjs-copy.css
*/
.hljs-copy-wrapper {
position: relative;
overflow: hidden;
}
.hljs-copy-wrapper:hover .hljs-copy-button,
@lunule
lunule / splidejs--multiple-on-same-page.js
Created May 24, 2024 00:53
[Splide JS - Multiple Sliders on the Same Page] #splide #multiple #sliders
const opts = {
// ...
}
document.querySelectorAll('.my-splide-class').forEach( function(carousel) {
const mySplide = new Splide( carousel, opts );
// ...