Skip to content

Instantly share code, notes, and snippets.

View pavlo-bondarchuk's full-sized avatar
🏠
remote

Pavlo Bondarchuk pavlo-bondarchuk

🏠
remote
View GitHub Profile
@pavlo-bondarchuk
pavlo-bondarchuk / php
Last active March 10, 2025 15:22
get_wp_menu_by_chunk
function get_wp_menu_by_chunk($menu_location, $max_items_per_column = 5)
{
$menu_locations = get_nav_menu_locations();
if (!isset($menu_locations[$menu_location])) {
return;
}
$menu = wp_get_nav_menu_object($menu_locations[$menu_location]);
if (!$menu) {
return;
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Last active February 28, 2025 09:31
Redirects single post URLs to their correct language-specific category URLs
<?php
add_action('template_redirect', function () {
global $post, $wp_query;
if (function_exists('wpml_get_language_information')) {
$current_lang = apply_filters('wpml_current_language', null);
if ($current_lang !== 'he') {
return;
}
@pavlo-bondarchuk
pavlo-bondarchuk / Disable WP REST API - Contact Form 7 Endpoints
Created August 15, 2024 16:46 — forked from petermann/Disable WP REST API - Contact Form 7 Endpoints
Automatically Enable Contact Form 7 Endpoints with Disable WP REST API Plugin
/**
* Automatically Enable Contact Form 7 Endpoints with Disable WP REST API Plugin
* Plugin URI: https://wordpress.org/plugins/disable-wp-rest-api/
*/
function disable_wp_rest_api_enable_contact_form7_endpoints() {
$active_plugins = get_option('active_plugins');
// Check if the "Disable WP REST API" plugin is active
if (in_array('disable-wp-rest-api/disable-wp-rest-api.php', $active_plugins)
// Check if the "Contact Form 7" plugin is active
&& in_array('contact-form-7/wp-contact-form-7.php', $active_plugins)
@pavlo-bondarchuk
pavlo-bondarchuk / html
Created July 24, 2024 22:23
use svg - right way
<main>
<svg class="icon">
<use xlink:href="#icon"></use>
</svg>
</main>
<footer>
<!-- some content-->
<!-- inline svg in html -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
@pavlo-bondarchuk
pavlo-bondarchuk / php
Created July 24, 2024 21:58
add_preload_featured_image
function add_preload_featured_image() {
if (is_single() || is_page()) {
if (has_post_thumbnail()) {
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_image_url($post_thumbnail_id, 'full');
if ($post_thumbnail_url) {
echo '<link rel="preload" href="' . esc_url($post_thumbnail_url) . '" as="image" type="image/webp">';
}
}
@pavlo-bondarchuk
pavlo-bondarchuk / bypass-elementors-maintenance-mode.php
Created April 4, 2024 13:29 — forked from mishterk/bypass-elementors-maintenance-mode.php
Using this snippet, you can bypass Elementor's maintenance mode by adding ?bypass_maintenance=1 to the query string
<?php
add_filter( 'pre_option_elementor_maintenance_mode_mode', function ( $option ) {
$parameter = 'bypass_maintenance'; // change this to whatever you like
if ( isset( $_GET['bypass_maintenance'] ) and $_GET['bypass_maintenance'] ) {
return 0; // needs to be falsy but not FALSE
}
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Created April 3, 2024 11:49
gittify custom theme development
<?php
// Automatic theme updates from the GitHub repository
add_filter('pre_set_site_transient_update_themes', 'automatic_GitHub_updates', 100, 1);
function automatic_GitHub_updates($data) {
// Theme information
$theme_dtls = array(
'theme_parent' => get_option('template'),
'theme_parent_uri' => get_template_directory_uri(),
'theme_name' => get_option('stylesheet'),
'theme_template' => get_stylesheet_directory(), // Folder name of the current theme
@pavlo-bondarchuk
pavlo-bondarchuk / toc.js
Last active February 27, 2024 13:49
TOC Class
/**
* Author: Dakota Lee Martinez
* Url: https://dakotaleemartinez.com/tutorials/how-to-add-active-highlight-to-table-of-contents/
* Thanks!
*/
class Scroller {
static init() {
if (document.querySelector('.sticky-toc')) {
this.tocLinks = document.querySelectorAll('.sticky-toc a');
this.headers = Array.from(this.tocLinks).map(link => {
@pavlo-bondarchuk
pavlo-bondarchuk / custom-languge-swicther-schortcode.php
Created July 13, 2023 19:02 — forked from evtihii/custom-languge-swicther-schortcode.php
Translatepress custom language switcher shortcode
<?php
/*
* Custom language switcher shortcode
*/
function trpc_language_switcher($atts)
{
ob_start();
global $TRP_LANGUAGE;
@pavlo-bondarchuk
pavlo-bondarchuk / *.php
Created February 20, 2023 12:45
send notifications to telegram about wc orders
function usual_tg( $message ) {
$token = '';
$chatids = [ ];
if ( stristr( $message, 'http' ) === false ) {
foreach ( $chatids as $chatid ) {
wp_remote_get( "https://api.telegram.org/bot$token/sendMessage?chat_id=$chatid&text=$message&parse_mode=HTML" );
}
}
}