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 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' );
@tiendungdev
tiendungdev / functions.php
Created February 13, 2020 03:13
Adding Search To The Wordpress Menu
/**
* Add search box to secondary menu
*/
function wpgood_nav_search($items, $args) {
// If this is the secondary menu?
if( ($args->theme_location == 'menu-2') )
// Add the form
return $items . '<li class="nav-search"><i class="fa fa-search"></i><i class="fa fa-times"></i></li>';
// Otherwise just return the nav items
return $items;
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID, // Get this pages id and find the children
'order' => 'ASC',
'orderby' => 'menu_order'
);
@tiendungdev
tiendungdev / loop.php
Created February 13, 2020 02:53
Loop to Get all sub-page of parrent
<?php
//Source: https://thuthuat.vip/
global $post;
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
//'post_parent' => $post->ID, // Get this pages id and find the children
'post_parent' => array('2455', '2447'),
'post_parent__in' => array('2455', '2447'),
'order' => 'ASC',
@tiendungdev
tiendungdev / .htaccess
Created December 13, 2019 15:56 — forked from seoagentur-hamburg/.htaccess
UPDATE 2019/07: Perfect .htaccess file for highspeed and security. You can use it for every WordPress-Website without problems. Highspeed and Security - testet on hundreds of Websites. If you are using a WordPress Multisite, change the last part of this file.
########################################################################
# OPTIMAL .htaccess FILE FOR SPEED AND SECURITY @Version 2019
# ----------------------------------------------------------------------
# @Author: Andreas Hecht
# @Author URI: https://andreas-hecht.com
# License: GNU General Public License v2 or later
# License URI: http://www.gnu.org/licenses/gpl-2.0.html
########################################################################
/* Delete post ajax
*===============================================================*/
add_action('wp_ajax_moveposttotrash', function(){
check_ajax_referer( 'trash-post_' . $_POST['post_id'] );
wp_trash_post( $_POST['post_id'] );
die();
});
/* Add new js in adminpage
*===============================================================*/
jQuery(function($){
$('body.post-type-post .row-actions .trash a').click(function( event ){
event.preventDefault();
var url = new URL( $(this).attr('href') ),
nonce = url.searchParams.get('_wpnonce'), // MUST for security checks
row = $(this).closest('tr'),
postID = url.searchParams.get('post'),
postTitle = row.find('.row-title').text();