Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / scroll.js
Created November 27, 2024 13:49
Horizontal Scroll Native
function nativeHorizontalScroll( id ) {
var elID = id;
var element = document.getElementById( id );
var scrolling = false;
var initialX = 0;
function getParent( node, id ) {
if ( node.id === id ) {
return node;
}
@igorbenic
igorbenic / desc.php
Last active October 13, 2026 09:41
How to Programmatically Change Yoast SEO Open Graph Meta | http://www.ibenic.com/programmatically-change-yoast-seo-open-graph-meta
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_desc', 'change_desc' );
}
function change_desc( $desc ) {
// This article is actually a landing page for an eBook
if( is_singular( 123 ) ) {
@igorbenic
igorbenic / abstract-1.php
Last active September 13, 2026 10:10
How to build WordPress Settings API as Framework | ibenic.com
<?php
namespace MySettingsFramework;
abstract class Settings {
/**
* Setting ID. Prefixes all options.
* @var string
*/
@igorbenic
igorbenic / new.js
Created June 23, 2023 19:28
Programmatically Add a Block to WordPress | ibenic.com
var block = wp.blocks.createBlock('core/paragraph', {content: 'From Console'});
wp.data.dispatch('core/block-editor').insertBlocks(block);
@igorbenic
igorbenic / modal.php
Last active July 25, 2026 22:20
Use YouTube API to Create a WordPress Video Modal | www.ibenic.com/use-youtube-api-to-create-a-wordpress-video-modal
<?php
add_action('wp_footer', 'youtube_video_html');
function youtube_video_html(){
?>
<div class="video_modal">
<button class="video_modal_close" onClick="closeVideo();">x</button>
<div id="videoPlayer"></div>
</div>
<?php
@igorbenic
igorbenic / checkout-1.js
Created May 26, 2023 15:09
How to add a City Dropdown to WooCommerce Checkout
jQuery( function( $ ) {
var cities = wc_city_dropdown.cities;
wrapper_selectors = '.woocommerce-billing-fields,' +
'.woocommerce-shipping-fields,' +
'.woocommerce-address-fields';
$( document.body ).on( 'change refresh', 'select.country_to_state, input.country_to_state', function() {
var $wrapper = $( this ).closest( wrapper_selectors );
@igorbenic
igorbenic / clauses.php
Last active May 20, 2026 07:31
Extending WP_Query with Custom Queries and Tables | https://www.ibenic.com/extending-wp-query-custom-queries-tables
<?php
add_filter( 'posts_clauses', 'filter_clauses', 10, 2 );
/**
* Filtering everything.
*
* @param array $clauses Array with all parts of the query.
* @param WP_Query $wp_query Object.
* @return string
@igorbenic
igorbenic / widget-recent-posts.php
Created May 4, 2023 01:20
Developer Challenge: Create a Custom WordPress Widget | subscribe for more at https://www.ibenic.com/newsletter/
<?php
/**
* Plugin Name: Recent Widget Challenge from ibenic.com/newsletter
*/
/*
You will create a custom WordPress widget that displays a list of the most recent posts.
Each recent post should have:
@igorbenic
igorbenic / block.js
Last active October 22, 2025 10:42
Gutenberg Components: Autocompleter
// https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/autocompleters/block.js
// ...
return {
name: 'blocks',
className: 'editor-autocompleters__block',
triggerPrefix: '/',
options() {
const selectedBlockName = getSelectedBlockName();
return getInserterItems( getBlockInsertionParentClientId() ).filter(
// Avoid offering to replace the current block with a block of the same type.
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty