Skip to content

Instantly share code, notes, and snippets.

View tiendungdev's full-sized avatar

Tien Dung Dao tiendungdev

View GitHub Profile
@tiendungdev
tiendungdev / functions.php
Created September 25, 2022 06:52
Thêm đơn hàng bằng PHP - Woocommerce
add_action('woocommerce_checkout_process', 'create_vip_order');
function create_vip_order() {
global $woocommerce;
$address = array(
'first_name' => 'Tien Dung',
'last_name' => 'Dao',
'company' => 'TTV',
@tiendungdev
tiendungdev / function.php
Created July 11, 2022 09:58
Simple shortcode with ob_start
<?php
function vts_shortcode_box(){
ob_start();
?>
<div class="box">Content blabla</div>
<?php
$result = ob_get_contents();
ob_end_clean();
return $result;
}
@tiendungdev
tiendungdev / style.css
Created April 8, 2022 09:31
Beautiful 404 error page - Flatsome theme
/*404*/
.error-404{padding:0; margin:0}
.error-404 .medium-3 {
max-width: 100%;
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
text-align: center;
font-size: 45px!important;
padding: 0;
margin: 0
@tiendungdev
tiendungdev / functions.php
Created February 4, 2022 05:43
Strong password
<?php
/**
* Enforce strong passwords (ESP) for all website users.
*
* To disable enforcing strong passwords:
* define('ESP_IS_ENABLED', false);
*/
if (!defined('WPINC')) {
exit('Do NOT access this file directly.');
@tiendungdev
tiendungdev / header.php
Created August 26, 2021 08:15
follow, noindex
<?php if(is_paged()){ echo '<meta name="robots" content="follow, noindex"/>'; } ?>
<?php
//check url neu co tu page thi cho noindex
$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($url,'page') !== false) {
echo '<meta name="robots" content="follow, noindex"/>';
}
?>
@tiendungdev
tiendungdev / functions.php
Created August 14, 2021 03:24
Preload Image WP
function preload_featured_image(){
if (has_post_thumbnail()) {
$attachment_image = wp_get_attachment_url( get_post_thumbnail_id() );
echo '<link rel="preload" as="image" href="'.$attachment_image.'">';
}
}
add_action('wp_head', 'preload_featured_image');
@tiendungdev
tiendungdev / functions.php
Created October 23, 2020 06:54
Thêm điều hướng breadcrumb vào WordPress
// WordPress Breadcrumb Function
function vts_breadcrumb() {
// Check if is front/home page, return
if ( is_front_page() ) {
return;
}
// Define
global $post;
/**
* Multi excerpt_length
*/
function vts_variable_excerpt_length( $length ) {
global $post;
if ( 'post' === $post->post_type ) {
return 32;
} else if ( 'page' === $post->post_type ) {
return 65;
@tiendungdev
tiendungdev / custom.php
Created April 10, 2020 12:29
Get child pages of a page in WordPress
<?php
$args = array(
'post_type' => 'page', //write slug of post type
'posts_per_page' => -1,
'post_parent' => '26', //place here id of your parent page
'order' => 'ASC',
'orderby' => 'menu_order'
);
@tiendungdev
tiendungdev / functions.php
Created April 10, 2020 04:09
Remove default widgets in WordPress
add_action( 'widgets_init', 'vts_remove_default_widgets' );
function vts_remove_default_widgets() {
unregister_widget( 'WP_Widget_Pages' );
unregister_widget( 'WP_Widget_Calendar' );
unregister_widget( 'WP_Widget_Archives' );
unregister_widget( 'WP_Widget_Links' );
unregister_widget( 'WP_Widget_Media_Audio' );
unregister_widget( 'WP_Widget_Media_Image' );
unregister_widget( 'WP_Widget_Media_Video' );
unregister_widget( 'WP_Widget_Media_Gallery' );