Skip to content

Instantly share code, notes, and snippets.

View developer-anuragsingh's full-sized avatar

Anurag Singh developer-anuragsingh

  • Cendyn
  • Gurugram
View GitHub Profile
@developer-anuragsingh
developer-anuragsingh / gist:ca98ee5e3c967f9ec5daa67388a714a2
Created July 5, 2019 13:45
Show menu of parent site in all multiple sites
// All sub-site drop down display
if (!function_exists('get_all_multisite_links')) {
function get_all_multisite_links($menu_name = 'Primary')
{
global $blog_id;
$current_blog_id = $blog_id; // Get current blog id
switch_to_blog(1); // change blog to 'parent site' (ID = 1)
$primaryNav = wp_get_nav_menu_items($menu_name);
$menu_object = wp_get_nav_menu_object($menu_name);
?>
<?php
add_action('registered_post_type', 'make_posts_hierarchical', 10, 2);
function make_posts_hierarchical($post_type, $pto)
{
if ($post_type != 'post') return; // Return, if not post type posts
global $wp_post_types; // access $wp_post_types global variable
@developer-anuragsingh
developer-anuragsingh / function.php
Created June 17, 2019 07:40
WP - Taxonomy filters through Ajax
/ Add this code in function.php file
// Taxonomy Filter through Ajax without Submit button
require get_stylesheet_directory() . '/template-parts/content/taxonomy-filters-ajax.php';
@developer-anuragsingh
developer-anuragsingh / functions.php
Last active June 14, 2019 10:44
Add a dropdown filter for wordpress taxonomies
function get_terms_dropdown_type($taxonomy, $args)
{
$taxo_obj = get_taxonomy($taxonomy);
$taxo_singular_name = $taxo_obj->labels->singular_name;
$terms_obj = get_terms($taxonomy, $args);
if ('category' === $taxonomy) {
$taxonomy_name = 'cat';
} elseif ('post_tag' === $taxonomy) {
$taxonomy_name = 'tag';
@developer-anuragsingh
developer-anuragsingh / gist:e309d49e0fe1ea84b0071663bba39302
Created June 13, 2019 10:52
WP - Update post's taxonomy terms and slug programmatically (PHP, Wordpress)
// List of post need to modify.
// $posts = array(
// array(
// 'id' => 1,
// 'term' => get_term_id_by_name(array('parent', 'child')),
// 'taxonomy' => 'category',
// ),
// array(
// 'id' => 5,
// 'term' => get_term_id_by_name(array('parent')),
@developer-anuragsingh
developer-anuragsingh / custom-function.php
Created June 11, 2019 06:22
Add script only on homepage
// Add script only on homepage
add_action('wp_footer', 'add_script_on_homepage');
function add_script_on_homepage() {
if( is_page( 'Home' ) || is_home() || is_front_page()) {
?>
<script>
...
...
...
</script>
CMD to Check VIP Coding standard phpcs --standard=WordPressVIPMinimum,WordPress,WordPress-Docs /data1/betaie/wp-content/themes/vip/indianexpress/template-parts/sports/ipl/stats-table-data.php
CMD to fix VIP Coding standard phpcbf --standard=WordPressVIPMinimum,WordPress,WordPress-Docs /data1/betaie/wp-content/themes/vip/indianexpress/template-parts/sports/ipl/stats-table-data.php
phpcs --standard=WordPressVIPMinimum,WordPress,WordPress-Docs /home/online/Documents/PHPCS/file.php
Install compose
Open VS Code IED
Install Extention phpcs
Open Terminal ctr + `
Navigate to Local Server's main directory Ex - C:\xampp\htdocs\
Create folder 'wpcs' in main directory (command) composer create-project wp-coding-standards/wpcs --no-dev
VS Code Extentions Name Developer Language
-------------------------------------------------------------------------------------------------------
--------------
Theme & Colors
--------------
Material Theme - Mattia Astorino
----------------------------------------
Perform checks as per PHPCS stadard
----------------------------------------
phpcs --standard=WordPressVIPMinimum,WordPress,WordPress-Docs [File name along with full path]
-------------------------------------------------------
Automatic fixes with PHPCBF Stadards
-------------------------------------------------------
phpcbf --standard=WordPressVIPMinimum,WordPress,WordPress-Docs [File name along with full path]
@developer-anuragsingh
developer-anuragsingh / Google reCaptcha 3
Last active January 20, 2023 11:13
Add Google reCaptcha 3 (invisible) on frontend & backend in PHP | HTML | jQuery
- Add Google reCaptcha 3 on HTML form
- On form load, get the google recaptcha response in hidden form field
- On form submit, Send recaptha field value to php file
- Validate google captcha with server side