Skip to content

Instantly share code, notes, and snippets.

View mennwebs's full-sized avatar

Menn mennwebs

View GitHub Profile
@mennwebs
mennwebs / single.php
Last active March 2, 2021 02:19
Thai date from ACF date - formart YYYYMMDD
<?php
$acf_date = get_field($date_field, false, false);
$buddhist_year = (int)substr($acf_date, 0, 4) + 543;
echo date_i18n('j F ', strtotime($acf_date)) . $buddhist_year;
@mennwebs
mennwebs / functions.php
Created July 31, 2019 12:15
Change Excerpt Length (WordPress)
<?php
/**
* Excerpt change from 50
*/
function seed_excerpt_length( $length ) {
return 100; // Thai uses "Characters", English uses "Words"
}
add_filter( 'excerpt_length', 'seed_excerpt_length', 900 );
function seed_excerpt_more( $more ) {
@mennwebs
mennwebs / functions.php
Last active July 24, 2019 14:06
แก้ความยาว Excerpt ของ WordPress (default: 50)
<?php
/**
* Excerpt change from 50
*/
function seed_excerpt_length( $length ) {
return 100;
}
add_filter( 'excerpt_length', 'seed_excerpt_length', 100 );
function seed_excerpt_more( $more ) {
@mennwebs
mennwebs / style.scss
Last active July 23, 2019 12:36
No margin for last child (p, ol, ul, ...) in div.box
.box {
> :last-child {
margin-bottom: 0;
}
}
@mennwebs
mennwebs / functions.php
Last active July 24, 2019 14:07
Advanced Forms Pro - สร้างโพสต์ใหม่ เปิด comment กับ save featured image ให้ด้วย
<?php
/**
* AdvanceForms
*/
function form_post_created( $post, $form, $args ) {
$post->comment_status = 'open';
wp_update_post( $post );
update_post_meta($post->ID, '_thumbnail_id', get_field('pic', $post->ID));
}
add_action( 'af/form/editing/post_created', 'form_post_created', 10, 3 );
@mennwebs
mennwebs / front-page.php
Last active July 24, 2019 14:07
แสดง Event (CPT) หน้าแรก เรียงตามวันที่จะมาถึง
<?php
$args = array(
'posts_per_page' => 5,
'post_type' => 'event',
'meta_key' => 'date',
'meta_value' => date("Ymd"),
'meta_compare' => '>',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
@mennwebs
mennwebs / style.css
Created May 28, 2019 12:38
CSS สำหรับเปลี่ยนค่าตามขนาดหน้าจอต่างๆ โดยทำแบบ Mobile First คือเริ่มจากจอเล็กไปใหญ่
// ใส่ CSS สำหรับแสดงผล Mobile เช่น
.test {
font-size: 12px;
}
@media (min-width: 768px) {
// โค้ด CSS สำหรับจอ iPad แนวตั้ง เช่น
.test {
font-size: 14px;
}
@mennwebs
mennwebs / functions.php
Last active July 24, 2019 14:08
WooCommerce เรียงลำดับจังหวัด เวลาแสดงผลภาษาไทย
<?php
/* Custom Thai Province Order */
if (get_locale() == 'th') {
add_filter( 'woocommerce_states', 'seed_woocommerce_states' );
}
function seed_woocommerce_states( $states ) {
$states['TH'] = array(
'TH-81' => 'กระบี่',
'TH-10' => 'กรุงเทพมหานคร',
'TH-71' => 'กาญจนบุรี',
@mennwebs
mennwebs / functions.php
Created January 9, 2019 06:30 — forked from jay7793/functions.php
Sample WooCommerce API Product Update (พี่เม่น)
<?php
ติดตั้ง Woocommerce php sdk โดยใช้คำสั่งด้านล่างนี้ (ใช้ Command ในการตัดตั้ง)
// composer require automattic/woocommerce
// Setup:
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
function wc_init() {
@mennwebs
mennwebs / Seed Social SCSS - ปุ่มติดกัน
Created November 25, 2018 05:40
แบบเว็บ SeedThemes.com
body .seed-social {
> div {
margin-right: 0;
margin-bottom: 0;
&.line {
margin-right: 0;
a {
border-radius: 0 3px 3px 0;
}
}