Skip to content

Instantly share code, notes, and snippets.

View gr1zix's full-sized avatar
🎯
Focusing

Grizix gr1zix

🎯
Focusing
View GitHub Profile
@gr1zix
gr1zix / index.js
Created March 10, 2025 13:36
[JS Async DOM] Wait until async element will be added to the DOM then handle it
function waitForElement(selector, timeout = 5000) {
return new Promise((resolve, reject) => {
const startTime = Date.now();
function check() {
const element = document.querySelector(selector);
if (element) {
return resolve(element);
}
if (Date.now() - startTime >= timeout) {
@gr1zix
gr1zix / functions.php
Last active October 26, 2024 18:19
Disable logo link on home/front page in Wordpress
<?php
function my_theme_setup() {
add_theme_support('custom-logo',
array(
'height' => 100,
'width' => 100,
'flex-width' => true,
'flex-height' => true,
'unlink-homepage-logo' => true, // add this rule to disable logo on homepage. See: https://developer.wordpress.org/reference/functions/get_custom_logo/
)
@gr1zix
gr1zix / yoast-reindex.md
Last active September 22, 2024 20:25
Yoast: Reset Index Tables

How to reset the Yoast indexables Source

  • Go to Add new plugin and install Yoast Test Helper
  • Next, go to Tools > Yoast Test and click on Reset Indaxable tables & migrations
  • Then go to Yoast > Tools and press Start SEO data optimization
    • If Start SEO data optimization button in not active needed add to wp-config.php file constant define( 'WP_ENVIRONMENT_TYPE', 'production' ); Source

Cases when I used it:

  • When Breadcrumbs and JSON-LD generation not added taxonomy (category) to the list;
  • When I changed the category taxonomy slug to categories and it was added to breadcrumbs and JSON-LD with domain.com/category/abc;
@gr1zix
gr1zix / function.php
Created July 25, 2024 18:53
Lazyload images for content in WordPress
<?php
add_filter('the_content', 'add_loading_attribute_to_content_images_for_lazyload');
function add_loading_attribute_to_content_images_for_lazyload($content) {
// Find all images in the content
preg_match_all('/<img[^>]+>/i', $content, $images);
if (!empty($images[0])) {
foreach ($images[0] as $index => $image) {
// Check if image already has loading attribute
if (str_contains($image, 'loading=')) {
@gr1zix
gr1zix / solution.md
Created July 14, 2024 15:59
Way to regain access to Mysql in Docker (Laradock) when database was change from Mysql 8 to 9

Way to regain access to mysql in Docker (Laradock)

It's short tutorial for you if your database was created in Mysql 8, and now it upgraded to Mysql 9 where native password plugin was removed.

How it happened:

I was using Mysql 8. But today I noticed that my Docker has grown too much, so I decided to clean up the outdated files. But I accidentally deleted the built images.

After that, I've re-build my Laradock stack and noticed that the Mysql container started to give an error, as it turned out it was an error about the unknown variable mysql_native_password.

I tried different approaches that I used to fix it before and nothing helped. Later, I searched a ton of material, but nothing really worked.

@gr1zix
gr1zix / index.js
Last active July 7, 2024 19:34
Stop all active Ajax requests in jQuery + Prevent Wordpress request abuse
$.xhrPool = {
pool: [],
abortAll: function() {
$.each(this.pool, function(idx, jqXHR) {
jqXHR.abort();
});
this.pool = [];
},
add: function(jqXHR) {
this.pool.push(jqXHR);
@gr1zix
gr1zix / MyToken.sol
Created June 8, 2024 19:50
Solidity token contract example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
@gr1zix
gr1zix / MyNFT.sol
Created June 8, 2024 19:31
NFT Smart-contract example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC165 {
function supportsInterface(bytes4 interfaceID)
external
view
returns (bool);
}
@gr1zix
gr1zix / gutenberg-button.js
Created June 2, 2024 11:54 — forked from junaidbhura/gutenberg-button.js
WordPress Gutenberg open button in a new window
/**
* Button.
*/
import wp from 'wp';
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
const { createHigherOrderComponent } = wp.compose;
const { Fragment, cloneElement } = wp.element;
@gr1zix
gr1zix / function.php
Created April 16, 2024 17:04 — forked from mattclements/function.php
Wordpress Disable Comments (add to function.php)
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}