Skip to content

Instantly share code, notes, and snippets.

@neilgee
neilgee / markup.php
Last active January 31, 2021 15:56
WordPress Media Uploader For Multiple Images
<?php
/* One of the upload fields as an example */
?>
<tr>
<th><label for="ols_user_meta_image_1"><?php _e( 'OLS Image 1', 'textdomain' ); ?></label></th>
<td>
<!-- Outputs the image after save -->
<img src="<?php echo esc_url( get_the_author_meta( 'ols_user_meta_image_1', $user->ID ) ); ?>" style="width:150px;"><br />
<!-- Outputs the text field and displays the URL of the image retrieved by the media uploader -->
@carasmo
carasmo / example-cmb2-repeatable-group.txt
Last active June 21, 2022 01:42
example CMB2 repeatable group
/** ====================================================================================
* Functions file
==================================================================================== **/
function yourthemeprefix_yourcpt_metabox_register() {
$prefix = '_cmb_';
@dleone81
dleone81 / functions.php
Last active June 27, 2024 18:42
Woocommerce get product type
/**
* is_type can be simple, variable, grouped, external
* woocommerce_single_product_summary is hook!
* Put this into your functions.php (child-theme)
**/
add_action( 'woocommerce_single_product_summary', 'get_product_type', 5 );
function get_product_type() {
global $post;
if( function_exists('get_product') ){
$product = get_product( $post->ID );
@kailoon
kailoon / custom-body-class.php
Last active April 20, 2023 10:03
Theme authors should avoid and not to hardcode custom body_class. Main reason for this is being able to remove the class when needed i.e. child themes.
<?php
// if there's a namespace, add it the body class
$classes[] = esc_attr( $theme_options['themename_namespace'] );
if ( isset( $post ) ) {
$classes[] = esc_attr( $post->post_type . '_' . $post->post_name );
}
if (is_single() ) {
foreach((wp_get_post_terms( $post->ID)) as $term) {
<?php
/*
* Note! This is no longer updated here in the Gist. It has been moved to a repo.
*
* @link https://github.com/daggerhart/wp-custom-menu-items
*/
/**
* Class custom_menu_items
@thanhluu
thanhluu / codeship.io.yml
Created October 21, 2015 02:50
Test WordPress Theme from Bitbucket on Codeship
cd ..
# Install CodeSniffer for WordPress Coding Standards checks.
git clone https://github.com/squizlabs/PHP_CodeSniffer.git php-codesniffer
# Install WordPress Coding Standards.
git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wordpress-coding-standards
# Hop into CodeSniffer directory.
cd php-codesniffer
# Set install path for WordPress Coding Standards
scripts/phpcs --config-set installed_paths ../wordpress-coding-standards
# After CodeSniffer install you should refresh your path.
@AlexanderPoellmann
AlexanderPoellmann / cleanup-woocommerce-db.sql
Created October 11, 2015 17:52
Clean up your database by deleting ALL (!) woocommerce sessions and ALL (!) transients. Use with caution!
DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\wc_session\_%')
DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\_transient\_%')
@daggerhart
daggerhart / Simple-PHP-Website.md
Created October 10, 2015 18:23
A very simple php website and contact form tutorial.

Simple PHP Website and Contact Form

This is purely for example and educational purposes.

The resulting contact form you will create with this example is extremely insecure. Do not use it on a live website.

Setup Environment

  1. Create website directory on Desktop
  2. Open terminal and test PHP php --version
@steveh80
steveh80 / grid.scss
Last active April 16, 2020 10:32
Bootstrap viewport detection in Javascript
// needed for viewport size detection in javascript
body::before {
display: none;
content: "xs";
}
@media (min-width: $screen-sm-min) {
body::before {
content: "sm";
}
<?php
// To be used by theme authors to avoid duplicate favicon code now that Site Icons have been added to WordPress 4.3
// If a Site Icon hasn't been set or if the `has_site_icon` function doesn't exist (ie older than WordPress 4.3)
if ( ! ( function_exists( 'has_site_icon' ) && has_site_icon() ) ) {
// your theme specific custom favicon code goes here
}