This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Adds widget: Categories | |
class RutuCategories_Widget extends WP_Widget { | |
function __construct() { | |
parent::__construct( | |
'rutu_categories_widget', | |
esc_html__( 'Rutu Categories', 'mfl' ), | |
array( 'description' => esc_html__( 'Custom Categories widget.', 'mfl' ), ) // Args |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- What is Functions File in WordPress? --> | |
<!-- Functions file commonly known as functions.php file is a WordPress theme file. | |
It comes with all free and premium WordPress themes. | |
The purpose of this file is to allow theme developers to define theme features and functions. This file acts just like a WordPress plugin and can be used to add your own custom code snippets in WordPress. | |
You would find many of these code snippets on websites like https://deardorffassociatesweb.wordpress.com/ with instructions telling you to add this code in your theme’s functions.php file or a site-specific WordPress plugin. | |
Now you may be thinking what’s the difference between a site-specific WordPress plugin and functions.php file? Which one is better? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $attributes = $product->get_attributes() // GET ALL ATRIBUTES ?> | |
<?php foreach( $attributes as $key => $value ): ?> | |
<?php $attribute_name = preg_replace( '/pa_/', '', $key ) // GET ATTRIBUTE NAME ?> | |
<label> | |
<select name="attribute_pa_<?php echo $attribute_name ?>" id="attribute_pa_<?php echo $attribute_name ?>"> | |
<option value=""><?php echo $attribute_name ?></option> | |
<?php $attribute_name = wc_get_product_terms( get_the_ID(), $key ) // GET ATTRIBUTE NAME ?> | |
<?php $attribute_slug = wc_get_product_terms( get_the_ID(), $key, array( 'fields' => 'slugs' ) ) // GET ATTRIBUTE SLUG ?> | |
<?php for ( $i=0; $i<count( $attribute_name ); $i++ ): // array_slice BECAUSE ARRAY INDEX IS NOT SEQUENCIAL ?> | |
<option value="<?php $slug = array_slice( $attribute_slug, $i, 1 ); echo $slug[0]; ?>"><?php $name = array_slice( $attribute_name, $i, 1 ); echo $name[0]; ?></option> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add the product's gender as an attribute. | |
* | |
* The attribute "Gender" with a slug of "gender" must already exist here: WordPress Admin Area > Products > Attributes | |
* | |
* @param array|string $value The current value of the $attribute for this $post. | |
* @param string $attribute The slug of the attribute. Examples: pa_color or pa_shoe-size | |
* @param array $post An array of post data including ID, post_title, post_status, etc... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php require __DIR__ . '/../htdocs/wp-load.php'; | |
// Decode products.json into an array of products. | |
$products = json_decode( file_get_contents( __DIR__ . '/products.json' ), true ); | |
// Now we want to loop through and create the top-level product. | |
foreach ( $products as $product ) { | |
/** | |
* A product is just a Wordpress post with a different 'post_type', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Change the add to cart text on product archives | |
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); // < 2.1 | |
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 + | |
function woo_custom_cart_button_text() { | |
return __( 'My Button Text', 'woocommerce' ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Restore CSV upload functionality for WordPress 4.9.9 and up | |
*/ | |
add_filter('wp_check_filetype_and_ext', function($values, $file, $filename, $mimes) { | |
if ( extension_loaded( 'fileinfo' ) ) { | |
// with the php-extension, a CSV file is issues type text/plain so we fix that back to | |
// text/csv by trusting the file extension. | |
$finfo = finfo_open( FILEINFO_MIME_TYPE ); | |
$real_mime = finfo_file( $finfo, $file ); | |
finfo_close( $finfo ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable scrollmagic controller on mobile | |
controller.scrollPos(function () { | |
if(window.innerWidth >= 576){ | |
return window.pageYOffset; | |
} else { | |
return 0; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function(){ | |
var aboutdata = null; | |
$.get( "/about-us/?ajax=true", function( data ) { | |
aboutdata = data; | |
$( "#menu-item-23" ).click(function() { | |
event.preventDefault(); | |
$( "body" ).html(aboutdata); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_enqueue_scripts', 'wps_load_scripts' ); | |
/** | |
* Enqueue Isotope | |
* For commercially developed child themes, you must obtain a license | |
* from isotope.metafizzy.co for approx. $25. | |
* | |
* @link http://isotope.metafizzy.co/ | |
* @link https://github.com/desandro/isotope | |
* @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script |