Skip to content

Instantly share code, notes, and snippets.

@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 / desc.php
Last active May 13, 2026 18:49
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 / 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 / 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 / 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 / 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 / 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
@igorbenic
igorbenic / add.php
Last active July 7, 2025 10:26
How to Add Custom Fields to WordPress Taxonomies | http://www.ibenic.com/custom-fields-wordpress-taxonomies
<?php
do_action( "{$taxonomy}_add_form_fields", string $taxonomy );
<?php
class WordPress_Custom_Status {
/**
* Post Types for this status
* @var array
*/
protected $post_type = array();