Skip to content

Instantly share code, notes, and snippets.

@cccamuseme
cccamuseme / create-custom-page-toxonomy.php
Last active April 10, 2025 17:54
Create Custom Page Taxonomy
// Create Page Category Custom Taxonomy (page post type)
function register_page_category_taxonomy() {
register_taxonomy('page_category', 'page', [
'label' => 'Page Categories',
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
]);
@cccamuseme
cccamuseme / remove-meta-box.php
Created September 20, 2024 15:10
Hide a meta box in WordPress. Customize the code and add to you themes functios file.
<?php
// Open your theme's functions.php file or create a custom plugin.
// Add the following code:
Add the following code:
function remove_custom_meta_boxes() {
// Example: remove the 'slugdiv' meta box from the post editor screen
remove_meta_box('slugdiv', 'post', 'normal');
@cccamuseme
cccamuseme / team-member-iso-filtering.php
Created September 11, 2024 16:50
Team Memeber CPT Isotope Filter
<?php
// Register and enqueue Isotope script
// Place in theme functions file
function cwpai_enqueue_isotope_script() {
wp_enqueue_script('isotope', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js', array('jquery'), '3.0.6', true);
}
add_action('wp_enqueue_scripts', 'cwpai_enqueue_isotope_script');
// Fetch Team Member posts
$args = array(
@cccamuseme
cccamuseme / create-shortcode-get-template-part.php
Last active April 29, 2025 15:11
Create Wordpress shortcode to get template part
// Add this code to your theme’s functions.php file:
function my_custom_shortcode() {
ob_start(); // Start output buffering
get_template_part('template-parts/my-template'); // Load the template part
return ob_get_clean(); // Return the buffered output
}
add_shortcode('myshortcode', 'my_custom_shortcode');
//This registers [myshortcode] which loads template-parts/my-template.php.
@cccamuseme
cccamuseme / acf-image-custom-image-size.php
Last active October 4, 2024 20:01
Display ACF image using custom image size - set acf to return image ID
// Use acf as image array
<?php
$image = get_sub_field('FIELD_NAME');
$image_url = $image['sizes']['CUSTOM_SIZE'];
?>
<img src="<?php echo $image_url; ?>">
<?php // don't copy this line in your code.
/**
* Remove uncategorized from the WooCommerce breadcrumb.
*
* @param Array $crumbs Breadcrumb crumbs for WooCommerce breadcrumb.
* @return Array WooCommerce Breadcrumb crumbs with default category removed.
*/
function your_prefix_wc_remove_uncategorized_from_breadcrumb( $crumbs ) {
$category = get_option( 'default_product_cat' );
$caregory_link = get_category_link( $category );
// Restricts input for the given textbox to the given inputFilter function.
function setInputFilter(textbox, inputFilter, errMsg) {
["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop", "focusout"].forEach(function(event) {
textbox.addEventListener(event, function(e) {
if (inputFilter(this.value)) {
// Accepted value
if (["keydown","mousedown","focusout"].indexOf(e.type) >= 0){
this.classList.remove("input-error");
this.setCustomValidity("");
}
@cccamuseme
cccamuseme / WP_Query_Arguments.php
Created April 20, 2022 20:11
WP_Query_Arguments
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
$args = array(
@cccamuseme
cccamuseme / woocommerce-hide-shipping-when-free-is-available.php
Last active January 26, 2022 15:32
Hide Woocommerce shipping rates when free shipping is available
<?php
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
@cccamuseme
cccamuseme / wordpress-dual-slick-slider.js
Created January 12, 2022 22:20
Wordpress Dual Slick Slider
jQuery(function($){
$('.slick-center').slick({
centerMode: true,
centerPadding: '25%',
slidesToShow: 1,
asNavFor: '.events-content',
responsive: [
{
breakpoint: 768,