Skip to content

Instantly share code, notes, and snippets.

@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
Created September 11, 2024 16:39
Create Wordpress shortcode to get template part
function shortcode_name_shortcode($atts) {
ob_start();
get_template_part('my-shortcode');
return ob_get_clean();
}
add_shortcode('shortcode_name', 'shortcode_name_shortcode');
@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; ?>">
@cccamuseme
cccamuseme / wp-shortcode-get-template-part.php
Last active August 24, 2023 18:39
Wordpress create shortcode to get template part
add_shortcode('my-shortcode', 'my_shortcode_function');
function my_shortcode_function($atts) {
ob_start();
get_template_part('template-parts/my-shortcode');
return ob_get_clean();
}
<?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("");
}
.row:after {
display: table;
content: " ";
clear: both;
}
.col1,
.col2,
.col3,
.col4,
@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();