Skip to content

Instantly share code, notes, and snippets.

View mennwebs's full-sized avatar

Menn mennwebs

View GitHub Profile
@mennwebs
mennwebs / functions.php
Created September 5, 2020 05:41
Create Home Page and set as home.
<?php
function sw_setup() {
if(get_option('page_on_front')=='0' && get_option('show_on_front')=='posts') {
// Create homepage
$homepage = array(
'post_type' => 'page',
'post_title' => 'Home',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1
@mennwebs
mennwebs / wp-config.php
Created September 4, 2020 01:46
Default Theme for Multisite
<?php
// Set the Default Theme for WordPress Multisite
define( 'WP_DEFAULT_THEME', 'plant' );
@mennwebs
mennwebs / thai-province.txt
Created May 31, 2020 13:12
The Province Name
กระบี่
กรุงเทพมหานคร
กาญจนบุรี
กาฬสินธุ์
กำแพงเพชร
ขอนแก่น
จันทบุรี
ฉะเชิงเทรา
ชลบุรี
ชัยนาท
@mennwebs
mennwebs / wp-config.php
Last active March 31, 2020 12:11
Mailgun for WP Multisite
<?php
// Ref: https://guides.wp-bullet.com/how-to-use-mailgun-with-wordpress-multisite-http-api-or-smtp/
//Mailgun multisite stuff
define('MAILGUN_USEAPI', true);
define('MAILGUN_APIKEY', 'key-YourAPIKeyHere');
define('MAILGUN_DOMAIN', 'mg.youdomain.com' );
define('MAILGUN_SECURE', true);
// Set the from name and from address
@mennwebs
mennwebs / page-account.php
Last active March 27, 2020 14:50
Show User Meta from WordPress
<?php $user = wp_get_current_user();?>
<h3 class="name"><?php echo $user->first_name . ' ' . $user->last_name;?></h3>
<div class="profile">
<div class="contact">
<p><?php echo $user->user_email; ?></p>
<p><?php echo $user->billing_phone; ?></p>
</div>
<div class="address">
<p>
<?php
@mennwebs
mennwebs / functions.php
Created March 22, 2020 10:20
Add Category Name to body_class
/* Add Category Name to body_class */
add_filter('body_class','moss_add_category_to_single');
function moss_add_category_to_single($classes) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
$classes[] = 'category-' . $category->category_nicename;
}
}
@mennwebs
mennwebs / front-page.php
Created December 15, 2019 07:49
ACF Repeater Headlines
<?php
/**
* ACF Repeater Field : headlines
* ACF Sub Field: headline (Post ID)
*/
$posts = array();
if (have_rows('headlines')) {
while (have_rows('headlines')) {
the_row();
@mennwebs
mennwebs / woo-tags.php
Created October 26, 2019 11:10
WooCommerce - Show Sale Percentage Tag - put in content-product.php
function seed_show_sale_percentage() {
global $product;
if ( $product->is_on_sale() ) {
if ( ! $product->is_type( 'variable' ) ) {
$max_percentage = ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100;
} else {
$max_percentage = 0;
foreach ( $product->get_children() as $child_id ) {
$variation = wc_get_product( $child_id );
$price = $variation->get_regular_price();
@mennwebs
mennwebs / af-acf.scss
Created October 8, 2019 14:17
SCSS for Advanced Forms + ACF
$line: #dcdfe5;
$primary: #339833;
$primary-active: #1c6808;
$gray: #878f9d;
div.acf-fields {
> .acf-field {
padding: 15px 16px;
@media (min-width: 768px) {
padding: 20px 30px;
@mennwebs
mennwebs / functions.php
Last active September 2, 2022 19:11
Use ACF image field as avatar
<?php
/**
* Use ACF image field as avatar
* @author Mike Hemberger
* @link http://thestizmedia.com/acf-pro-simple-local-avatars/
* @uses ACF Pro image field (tested return value set as Array )
*/
add_filter('get_avatar', 'acf_profile_avatar', 10, 5);
function acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
if ( is_numeric( $id_or_email ) ) {