Skip to content

Instantly share code, notes, and snippets.

View SchneiderSam's full-sized avatar

Samuel Schneider SchneiderSam

View GitHub Profile
@SchneiderSam
SchneiderSam / gist:73e66ea55d8a04b18af82d2c15ae0c6d
Last active April 18, 2024 08:29
Load Both Customizer and style.css into WordPress Block Editor
<?php
// Load CSS Variables in Editor
add_filter('block_editor_settings_all', function($editor_settings) {
$style_path = get_stylesheet_directory() . '/style.css';
if (file_exists($style_path)) {
$css_style = file_get_contents($style_path);
$editor_settings['styles'][] = ['css' => $css_style];
}
$customizer_css = wp_get_custom_css_post();
@SchneiderSam
SchneiderSam / gist:1d432f34e13a4934a1482e01a732b5af
Created September 19, 2023 07:15
Dynamic Content Replacement in WordPress with Jet Engine and GenerateBlocks
function replace_jet_engine_option_in_content($content) {
// Regular expression to detect all occurrences of {{any-slug::any-name}}
preg_match_all('/{{(.*?)::(.*?)}}/', $content, $matches);
if (!empty($matches) && isset($matches[0])) {
foreach ($matches[0] as $index => $match) {
// Get the slug and the option name
$page_slug = $matches[1][$index];
$option_name = $matches[2][$index];
@SchneiderSam
SchneiderSam / gp-mega-menu.php
Last active May 25, 2024 15:14 — forked from diggeddy/gp-mega-menu.php
Create a sub menu item container with action hook (Mega Menu with GeneratePress and GenerateBlocks)
<?php
add_filter( 'walker_nav_menu_start_el', 'db_sub_menu_item_hook', 10, 4 );
function db_sub_menu_item_hook( $item_output, $item, $depth, $args ) {
// Specify menu item class to target
$class_string = 'gp_mega_item';
$menu_item_classes = $item->classes;
if ( empty( $menu_item_classes ) || !in_array( $class_string , $menu_item_classes ) ) {
return $item_output;