Skip to content

Instantly share code, notes, and snippets.

View dexit's full-sized avatar
🎯
Focusing

Rihards Mantejs dexit

🎯
Focusing
View GitHub Profile
@dexit
dexit / archive-wpseo_locations.php
Created July 2, 2025 14:57 — forked from jdevalk/archive-wpseo_locations.php
A cool example of what your locations post type archive page could look like
<?php
/**
* Template for displaying a map on the locations post-type archive page.
*
* @package Twenty_Twelve
* @subpackage Local SEO for WordPress Archive page template
* @author Joost de Valk
*/
get_header();
@dexit
dexit / alt.php
Created July 2, 2025 14:56 — forked from seojacky/alt.php
Дописывание автоматически alt
/* Делаем alt для Превью поста
* Функция автозаполнения alt должна быть отключена в плагинах типа
* Webcraftic Clearfy или любом другом, который устанавливает alt автоматически, так как там всегда генерирует на основе заголовка
* В некоторых темах, например OceanWP alt прописан как заголовок статьи в самой теме, и там нужно дополнительно кодить
* в Astra всё нормально работает
*/
add_filter( 'wp_get_attachment_image_attributes', 'add_best_alt_attachment_image', 90, 2 );
function add_best_alt_attachment_image( $attr, $attachment ) {
//проверяем не заполнен ли уже alt
@dexit
dexit / search-wp-posts.sql
Created July 2, 2025 14:26 — forked from robwent/search-wp-posts.sql
Select Wordpress posts that contain a string in PhpMyAdmin
-- Change wp_ to your database prefix
-- Change domain.com to your domain
-- Change string to the text you want to search for
SELECT
ID as 'Post ID',
post_title as 'Title',
CONCAT('http://www.domain.com/',post_name) as 'URL'
FROM `wp_posts`
WHERE post_type = 'post'
// There seems to be a few algorithms floating around for brightness/luminance detection.
// One uses NTSC `(299*R + 587*G + 114*B)` which is incorrect for web colors (sRGB) see
// `rgbLuminance` for "better" coefficients (seems subjective but agreed apon). To be more
// accurate you need to also convert RGB from sRGB color space (which gives more spectrum to lighter colors)
// to linear rgb which normalizes colors across the spectrum - better for processing.
// see https://stackoverflow.com/questions/596216/formula-to-determine-perceived-brightness-of-rgb-color
// convert sRGB to linear RGB values
// - channel ** 2.218 same as Math.pow((channel + 0.055) / 1.055, 2.4)
// - i've seen this simplified to be just `(channel / 255) ** 2.21`
@dexit
dexit / functions.php
Created July 2, 2025 14:25 — forked from paulcollett/functions.php
Remove Yoast HTML Comments “This site is optimized with the Yoast WordPress SEO plugin”
// For Yoast SEO Plugin Version: 14.1+ add to your Wordpress Theme's functions.php...
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
// Credit @devendrabhandari (https://gist.github.com/paulcollett/4c81c4f6eb85334ba076#gistcomment-3303423)
add_filter( 'wpseo_debug_markers', '__return_false' );
// For Yoast SEO Plugin Version: < 14.1 add to your Wordpress Theme's functions.php...
@dexit
dexit / functions.php
Created July 2, 2025 14:25 — forked from robwent/functions.php
Remove Yoast HTML Comments “This site is optimized with the Yoast WordPress SEO plugin” with Yoast v11
//Remove Yoast HTML Comments
//https://gist.github.com/robwent/f36e97fdd648a40775379a86bd97b332
function go_yoast() {
if (defined('WPSEO_VERSION')){
add_action('get_header',function (){ ob_start(function ($o){
return preg_replace('/\n?<.*?Yoast SEO plugin.*?>/mi','',$o); }); });
add_action('wp_head',function (){ ob_end_flush(); }, 999);
}
}
<?php
/**
* Change min password strength.
*
* @author James Kemp (Iconic)
* @link http://iconicwp.com/decrease-strength-required-woocommerce-passwords/
* @param int $strength
* @return int
*/
function myclass_min_password_strength( $strength ) {
@dexit
dexit / yoast-schema.php
Created July 2, 2025 14:25 — forked from robwent/yoast-schema.php
Extends Yoast schema to add event data
<?php
include ("classes/Schema_Event.php");
add_filter( 'wpseo_schema_graph_pieces', 'PREFIX_add_graph_pieces', 11, 2 );
/**
* Adds Schema pieces to our output.
*
* @param array $pieces Graph pieces to output.
@dexit
dexit / Schema_Event.php
Created July 2, 2025 14:25 — forked from robwent/Schema_Event.php
Extends Yoast schema data to add events
<?php
use \Yoast\WP\SEO\Generators\Schema\Abstract_Schema_Piece;
class Schema_Event extends Abstract_Schema_Piece {
/**
* Determines whether or not a piece should be added to the graph.
*
* @return bool
<script>
if (window.jQuery) {
jQuery(document).ready(function() {
jQuery(document).on('submit_success', '.elementor-form', function(event) {
// Push the event to the dataLayer for Google Tag Manager
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'elementor_form_submission',
formName: event.target.getAttribute('name') ||
(event.target.querySelector('[name="form_id"]') ? event.target.querySelector('[name="form_id"]').value : 'unknown') ||