Skip to content

Instantly share code, notes, and snippets.

@SitesByYogi
SitesByYogi / product-search.php
Created December 27, 2024 11:58
Display a product search bar on your WordPress
<?php
// Add this code to your theme's functions.php file or use the Code Snippets plugin.
/**
* WooCommerce Product Search Bar Shortcode
*/
function custom_woocommerce_product_search_shortcode($atts) {
// Ensure WooCommerce is active
if (!class_exists('WooCommerce')) {
@SitesByYogi
SitesByYogi / display-blog.php
Last active December 27, 2024 11:56
Shortcode to Display Full Blog Post by Post ID Without Featured Image or Title
<?php
// Shortcode to Display Full Blog Post by Post ID Without Featured Image or Title
function display_full_post_no_image($atts) {
// Shortcode Attributes
$atts = shortcode_atts(array(
'id' => '', // Default: no post ID
), $atts, 'full_post_no_image');
// Validate the Post ID
@SitesByYogi
SitesByYogi / shoppable.php
Last active December 27, 2024 11:54
Creates shoppable template cpt
<?php
// Register Custom Post Type: Shoppable Articles
function create_shoppable_articles_post_type() {
$labels = array(
'name' => _x('Shoppable Articles', 'Post Type General Name', 'your-text-domain'),
'singular_name' => _x('Shoppable Article', 'Post Type Singular Name', 'your-text-domain'),
'menu_name' => __('Shoppable Articles', 'your-text-domain'),
'name_admin_bar' => __('Shoppable Article', 'your-text-domain'),
'archives' => __('Shoppable Article Archives', 'your-text-domain'),
<table class="bg-table table hide-header table-borderless" style="table-layout: fixed; width: 100%; height: 736px;">
<thead>
<tr style="height: 0px;">
<th style="width: 45%;">Header 1</th>
<th style="width: 40%;">Header 2</th>
<th style="width: 15%;">Header 3</th>
</tr>
</thead>
<tbody>
<!-- Your table rows here -->
@SitesByYogi
SitesByYogi / audio-ext.php
Last active September 6, 2024 19:38
Adds new fields to audio player
<?php
// Hook into the attachment fields
add_filter('attachment_fields_to_edit', 'add_custom_audio_fields', 10, 2);
add_filter('attachment_fields_to_save', 'save_custom_audio_fields', 10, 2);
// Function to add custom fields
function add_custom_audio_fields($form_fields, $post) {
// Only show these fields for audio files
if ($post->post_mime_type == 'audio/mpeg' || $post->post_mime_type == 'audio/wav' || $post->post_mime_type == 'audio/ogg') {
// Record Label field
@SitesByYogi
SitesByYogi / cpt.php
Created September 3, 2024 20:13
add custom post type
<?php
// Register the custom post type 'todo'
function todo_register_post_type() {
register_post_type('todo', array(
'labels' => array(
'name' => __('Content Creation Center'),
'singular_name' => __('Content'),
'add_new' => __('Add New Content'),
'add_new_item' => __('Add New Content'),
@SitesByYogi
SitesByYogi / apache.html
Created August 23, 2024 13:16
If your WordPress site is hosted on an Apache server, you can use the .htaccess file to add expiration headers and control the cache policy. Here’s an example of how you might configure it:
<IfModule mod_expires.c>
ExpiresActive On
# Set default expiration to 1 month
ExpiresDefault "access plus 1 month"
# Specific expiration times by file type
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
@SitesByYogi
SitesByYogi / conditional-script.php
Created August 22, 2024 17:42
Employ Conditional Script Loading
<?php
function load_scripts_based_on_browser() {
global $is_IE;
if (!$is_IE) {
// Modern browsers
wp_enqueue_script('modern-js', 'path_to_modern_script.js', array(), null, true);
} else {
// Legacy browsers
wp_enqueue_script('legacy-js', 'path_to_legacy_script.js', array(), null, true);
@SitesByYogi
SitesByYogi / webp-apache.html
Created August 22, 2024 13:19
Modify Your .htaccess File (for Apache Servers)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
RewriteRule (.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1]
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REDIRECT_accept
</IfModule>
<?php
function ezdump($variable){
echo '<pre>' . print_r($variable, true) . '</pre>';
}
$dataPoints1 = array();
function logToData($logname){
$logdata = file($logname);
$first = null;
foreach($logdata as $lineNumber => $logline){
$logline = explode(" " , $logline);