Skip to content

Instantly share code, notes, and snippets.

View rilwis's full-sized avatar
🙂
Happy and peace when coding

Anh Tran rilwis

🙂
Happy and peace when coding
View GitHub Profile
@rilwis
rilwis / admin-menu.php
Last active February 13, 2024 12:42
Move the admin menu for custom taxonomy in WordPress
<?php
add_action( 'admin_menu', 'prefix_move_taxonomy_menu' );
function prefix_move_taxonomy_menu() {
add_submenu_page( 'edit.php?post_type=quiz', esc_html__( 'Sections', 'mb-quiz' ), esc_html__( 'Sections', 'mb-quiz' ), 'manage_categories', 'edit-tags.php?taxonomy=question_section' );
}
@rilwis
rilwis / gist:a7ca4bc716c0036624d7068dd5742498
Created December 21, 2023 09:27
Set status 410 for deleted pages
<?php
add_action( 'template_redirect', function () {
if ( ! is_404() ) {
return;
}
$path = trim( $_SERVER['REQUEST_URI'] ?? '', '/' );
if ( $path === 'your-deleted-page' ) {
status_header( 410 );
@rilwis
rilwis / acf-block.php
Created December 7, 2023 05:01 — forked from razaanstha/acf-block.php
ContentEditable - ACF Block
<?php
/**
* Block: Hero
* --------------------------------
* The hero block for all pages.
*/
$block_data = get_fields();
?>
@rilwis
rilwis / single-room.php
Last active September 24, 2023 15:05 — forked from kutoi94/single-room.php
How to Build a Hotel Booking Website Using Meta Box (P3) - Template
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'single' );
the_post_navigation();
echo do_shortcode("[mb_frontend_form id='booking-fields' post_fields='title,content']");
@rilwis
rilwis / simple-meta-box.php
Created September 19, 2023 15:11
Test WP update button always active
<?php
// This code shows a simple meta box with a simple text, no inputs.
// And the "Update" button in WordPress is always active, e.g. never disabled, even if there's no changes, no updates.
add_action( 'add_meta_boxes', function() {
add_meta_box( 'test', 'Test', 'my_callback_func', 'post' );
} );
function my_callback_func() {
echo 'Just a text, and the Update button is always active.';
}
@rilwis
rilwis / remove-article-keywords.php
Created September 8, 2023 09:22
Slim SEO: Remove keywords from Article schema
<?php
add_filter( "slim_seo_schema_article", function ( $schema ) {
unset( $schema['keywords'] );
return $schema;
} );
@rilwis
rilwis / code.php
Created September 6, 2023 08:30
Slim SEO Schema: Remove hash in @id property
<?php
add_filter( 'slim_seo_schema_graph', function( $graph ) {
foreach( $graph as &$schema ) {
list( $url ) = explode( '#', $schema['@id'] );
$schema['@id'] = $url;
}
return $graph;
}, 20 );
@rilwis
rilwis / register.php
Created September 6, 2023 07:31
MB Relationships: change field type
<?php
add_action( 'mb_relationships_init', function () {
MB_Relationships_API::register( [
'id' => 'users_to_posts',
'from' => [
'object_type' => 'user',
'field' => [
'field_type' => 'checkbox_list',
],
],
@rilwis
rilwis / template.php
Created July 15, 2019 07:41 — forked from kutoi94/Meta Box Plugin
Use Meta Box to build the product detail page
<div class="page-wrapper">
<div class="product-gallery--columns-4 images" data-columns="4">
<figure class="product-gallery__wrapper">
<a href="<?php echo get_the_post_thumbnail('full'); ?>">
<img src="<?php echo get_the_post_thumbnail('full'); ?>" alt="<?php the_title(); ?>">
</a>
<div class="thumbnails owl-carousel owl-loaded owl-drag">
<div class="owl-stage-outer">
<div class="owl-stage">
<div class="owl-item">
@rilwis
rilwis / function.php
Last active January 31, 2020 09:20 — forked from kutoi94/function.php
How to Build a Hotel Booking Website Using Meta Box (P3) - functions.php
if ( ! get_option( 'rwmb_bookings' ) ) {
add_option( 'rwmb_bookings', array() );
}
add_action( 'rwmb_booking-fields_after_save_post', 'update_bookings_date' );
function update_bookings_date( $post_id ) {
$bookings = get_post_meta( $post_id, 'group_booking', true );