Skip to content

Instantly share code, notes, and snippets.

View nextab's full-sized avatar

nexTab - Oliver Gehrmann nextab

View GitHub Profile
@nextab
nextab / set one element to active and everything else to inactive
Created November 30, 2021 14:34
This snippet listens to events and after it recognizes a click from an element with the corresponding class ('.feature_blurb_button'), it iterates over all similar elements with the same class and sets them to inactive (= removes class ".active") and then toggles the class ".active" for the link target (inside the module we're clicking there is …
document.addEventListener('click', function (event) {
// console.log(event.target);
if (!event.target.matches('.feature_blurb_button')) return;
// find the link target set in the anchor elements inside the blurb
const toggleTargetParent = event.target.querySelector(".et_pb_module_header");
// console.log(toggleTargetParent);
const toggleTargetID = toggleTargetParent.children[0].getAttribute('href');
const toggleTarget = document.querySelector(toggleTargetID);
// console.log(toggleTarget);
@nextab
nextab / wp-config.php Hacks
Last active September 5, 2022 11:22
A collection of hacks for the WordPress wp-config.php.
# Salt-Link => https://api.wordpress.org/secret-key/1.1/salt/
# Repair-Link => https://example.com/wp-admin/maint/repair.php
# Settings-Link => https://example.com/wp-admin/options-general.php
# Debugging
define( 'WP_DEBUG', true ); # Aktiviert den Debug-Modus für PHP
define( 'SCRIPT_DEBUG', true ); # Aktiviert den Debug-Modus für CSS und JS
define( 'WP_DEBUG_LOG', true ); # Legt ein Fehlerprotokoll an => wp-content > debug.log
define( 'WP_DEBUG_DISPLAY', true ); # Zeigt Fehlermeldungen an
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); # Deaktiviert den eingebauten Recovery-Modus => Error Handler
@nextab
nextab / reset-password-snippet.php
Created December 20, 2021 14:45
This snippet allows you to change the default texts when someone is trying to request a new password in WordPress.
// Change the title of the password reset e-mail
function nxt_password_reset_title($title) {
$title = 'Passwort zurücksetzen für die Webseite XYZ';
return $title;
}
add_filter('retrieve_password_title', 'nxt_password_reset_title');
// Change the body text of the password reset e-mail
function nxt_retrieve_password_message( $message, $key, $user_login, $user_object) {
// $first_name = get_user_meta( $user_object->ID, 'first_name', true );
@nextab
nextab / change WordPress database collations from utf8 to utf8mb4
Created December 21, 2021 14:37
This little plugin allows you to change your database table collations from utf8 to utf8mb4. (This *usually* happens during an upgrade of WordPress, however, this action was only triggered ONCE and if your database wasn't "quite there yet" at the time (it didn't support utf8mb4), even if you keep updating WordPress, your database tables will NOT…
<?php
/**
*
* @link https://nextab.de
* @since 1.0.0
* @package nxt_utf8_conversion
*
* @wordpress-plugin
* Plugin Name: Convert Database collation to utf8mb4
* Plugin URI: https://nextab.de
@nextab
nextab / dynamically add body class to WordPress on custom post type and custom taxonomy
Created January 3, 2022 12:23
This little snippet looks for a custom field that was saved to a custom taxonomy (this is being accomplished with the Plugin Advanced Custom Fields) and if it finds a value there, it dynamically adds another body class to the body tag on your WordPress website.
function nxt_course_body_classes( $classes ) {
if(is_singular('lesson')) {
$kurs_taxonomy = get_the_terms(get_the_ID(), 'modules');
$tax_id = $kurs_taxonomy[0]->term_id;
$bg_position = get_field('nxt_cover_pos', 'modules_' . $tax_id);
} elseif(is_tax('modules')) {
$bg_position = get_field('nxt_cover_pos', 'modules_' . get_queried_object_id());
}
if($bg_position) {
$classes[] = 'nxt_cover_pos_' . $bg_position;
@nextab
nextab / Login - Logout Link in WordPress Hauptmenü aufnehmen
Created January 7, 2022 09:51
Snippet für die functions.php, mit dem dynamisch ein Login- bzw. Logout-Button erzeugt werden kann, abhängig davon, ob der Benutzer bereits eingeloggt ist oder eben nicht.
@nextab
nextab / Mobile Menu Icon in Divi zu x ändern bei geöffnetem Menü
Created January 11, 2022 12:28
Mit diesem Code Snippet ändert sich das Hamburger Menü Icon nach einem Klick zu einem "x", um zu zeigen, dass das Menü mit einem weiteren Klick wieder geschlossen werden kann.
.mobile_menu_bar::before {
display: block;
transition: all .4s ease;
}
.mobile_nav.opened .mobile_menu_bar::before {
content: "M";
transform: rotate(90deg);
}
@nextab
nextab / Custom Translations in WordPress für Theme oder Plugins über Child Theme einbinden.php
Created January 14, 2022 11:55
Check den Livestream vom 14.01.22 bis 1:23:36 um mehr Infos zur Notiz zu bekommen. ;-)
/* Die Funktion "load_child_theme_textdomain" ermöglicht es, ein Übersetzungs-File (de_DE.mo / de_DE.po) des jeweiligen Parent Themes über das Child Theme zu ersetzen. Konkretes Anwendungsbeispiel für Divi, bei dem die Standard-Übersetzung in Divi/lang und Divi/includes/builder/lang mit Übersetzungen im Child Theme Ordner ausgetauscht werden:
**Oder (nach Divi Updates funktioniert bei mir nur noch das):
/* Load Child Theme Language Files */
function nxt_translations() {
    // load custom translation file for the parent theme
    load_child_theme_textdomain( 'Divi', get_stylesheet_directory() . '/languages' );
    load_child_theme_textdomain( 'et_builder', get_stylesheet_directory() . '/languages/builder' );
@nextab
nextab / Disable Google Fonts in Elementor
Created January 28, 2022 11:00
Simply add this line of code to the functions.php of your child theme to disable Google Fonts in Elementor.
// Disable Google Fonts for Elementor
add_filter( 'elementor/frontend/print_google_fonts', '__return_false', 99999 );
@nextab
nextab / Beliebiges Datum formatiert in WordPress ausgeben
Last active February 8, 2022 15:57
Mit diesen beiden Code-Schnipseln lässt sich entweder das aktuelle Datum per PHP Code in WordPress ausgeben oder das Veröffentlichungsdatum eines Beitrags.
// Shortcode [releasedate] zeigt das AKTUELLE DATUM an.
function release_date_shortcode($atts, $content = null) {
$today = date_i18n('l, j. F Y');
return '<div class="date_container">Veröffentlicht am: ' . $today . '</div>';
}
add_shortcode('releasedate', 'release_date_shortcode');
// falls du das VERÖFFENTLICHUNGSDATUM des Beitrags ausgeben möchtest, verwende stattdessen diesen Code:
function release_date_shortcode($atts, $content = null) {