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 October 18, 2023 12:00
WP - Running No. Slug
<?php
// Running No. Slug
add_action('wp_insert_post', 'change_slug');
function change_slug($post_id, $force = false)
{
$post_types = ['news', 'faq'];
$post_type = $_POST['post_type'];
if (!in_array($post_type, $post_types) || get_field('no', $post_id)) {
return;
@mennwebs
mennwebs / style.css
Created February 26, 2023 08:51
Class _th and _en (show only Thai, English language)
._th:not(:lang(th)),
._en:not(:lang(en-US)) {
display: none !important;
}
@mennwebs
mennwebs / functions.php
Last active February 15, 2023 23:50
GenerateBlocks - Output CSS with Content (for Frontend, to get WordPress content via API)
// GENERATEBLOCKS CSS
if (function_exists('generateblocks_get_frontend_block_css')) {
add_filter('the_content', 'p_css');
}
function p_css($content) {
global $post;
$css = wp_strip_all_tags(generateblocks_get_frontend_block_css());
return '<style id="gb-css">' . $css . '</style>' . $content;
@mennwebs
mennwebs / functions.php
Created April 8, 2022 09:47
WP Shortcode to show Custom Field.
<?php
// Custom Field: demo_field
// Shortcode: [show_field]
function show_custom_field() {
$meta = get_post_meta( get_the_ID(), 'demo_field', true );
return '<em>' . $meta . '</em>';
}
add_shortcode('show_field', 'show_custom_field');
@mennwebs
mennwebs / functions.php
Created September 21, 2021 14:14
Seed Stat Pro - Change Post Views for specific Post ID.
<?php
add_filter('sstp_views', 'sstp_change_views',10, 2 );
function sstp_change_views($num, $postID) {
if ($postID == 123) {
return $num + 500;
}
return $num;
}
@mennwebs
mennwebs / front-page.php
Created July 18, 2021 10:07
Seed Stat - Most Popular (Last 30 Days)
<div class="most-popular">
<?php
$args = array(
'posts_per_page' => 5,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => 's_stat',
'date_query' => array(
'after' => '30 days ago'
)
@mennwebs
mennwebs / functions.php
Last active July 22, 2021 06:57
WP Shortcode for sending to Line Notify [s_line]
<?php
add_action( 'forminator_form_after_handle_submit', 'ws_get_message', 10, 2 );
add_action( 'forminator_form_after_save_entry', 'ws_get_message', 10, 2 );
// เก็บข้อความจากฟอร์มแล้วส่งไลน์
function ws_get_message($form_id, $response) {
// ===แก้ตรงนี้=====
@mennwebs
mennwebs / single.php
Created March 1, 2021 11:22
Show related post from "Related Posts for WordPress By Never5" WordPress Plugin
<?php // Show related post from "Related Posts for WordPress By Never5" WordPress Plugin
$p_id = get_the_ID();
$link_args = array(
'post_type' => 'rp4wp_link',
'posts_per_page' => 6,
'meta_query' => array(
array(
'key' => 'rp4wp_parent',
@mennwebs
mennwebs / acf-datepicker.js
Created January 27, 2021 09:29
ACF override minDate, maxDate in datepicker
jQuery(document).ready(function ($) {
acf.add_filter("date_picker_args", function (args, $field) {
if ($field.hasClass("birth_date")) {
args["minDate"] = "-8y"; //ref: https://api.jqueryui.com/datepicker/
args["maxDate"] = "-1d";
}
return args;
});
});
@mennwebs
mennwebs / functions.php
Created September 12, 2020 07:49
The SEO Framework - Limit only 1 image for social sharing
<?php
// from https://github.com/sybrew/the-seo-framework/issues/541
add_filter( 'the_seo_framework_image_generation_params', function( $params ) {
unset( $params['cbs']['content'] );
return $params;
} );