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
// Find value in PHP Associate array
Array
(
[0] => Array
(
[city_id] => 1
[city_name] => Abc
)
[1] => Array
<?php
/* Template Name: Demo - CPT with pagination
* Template will display listing of 'custom post type' along with pagination underneath (numerical style)
*/
?>
<?php get_header() ?>
<?php
$currentPage = get_query_var( 'paged' ); // Get var from query
@developer-anuragsingh
developer-anuragsingh / functions.php
Created December 9, 2017 10:39
WP - Add and retrieve posts data through REST API
<?php
// Add REST API related scripts
function add_script_for_rest_api() {
wp_enqueue_script('jquery-validate', get_stylesheet_directory_uri().'/assets/js/jquery.validate.min.js', array('jquery'), 1.17, true );
wp_enqueue_script('as-wp-api', get_stylesheet_directory_uri().'/assets/js/rest-api.js', array('jquery'), 1.0, true );
wp_localize_script( 'as-wp-api', 'wpApiSettings', array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' )
) );
}
@developer-anuragsingh
developer-anuragsingh / Load fresh CSS file each time
Last active January 15, 2018 08:21
Load fresh CSS file each time when that CSS file get modified. User will see the latest changes all time.
// Load fresh CSS file each time when that CSS file get modified (User will see the latest changes all time)
// Ref - https://developer.wordpress.org/reference/functions/wp_enqueue_style/#comment-2056
wp_enqueue_style('main-style', get_stylesheet_directory_uri() . '/assets/css/main.css', array(), filemtime(get_stylesheet_directory() . '/assets/css/main.css'), false);
@developer-anuragsingh
developer-anuragsingh / gist:d7fc05389a2436cb2512e815cff6fb55
Created December 14, 2017 13:56
How to Create a Simple WordPress Plugin
Wordpress Folder Structure
1 - wp-admin
2 - wp-content
3 - wp-includes
4 - .htaccess
5 - index.php
6 - wp-config.php
@developer-anuragsingh
developer-anuragsingh / ajax-login-script.js
Last active December 27, 2017 10:20
WordPress Custom Login Form
jQuery(document).ready(function($) {
// Perform AJAX login on form submit
jQuery('#as-login-form').on('submit', function(e){
event.preventDefault();
$error = 0;
var ajaxUrl = ajax_login_object.ajaxurl;
var username = jQuery("#username").val();
var password = jQuery("#password").val();
Angular
You need to set up your development environment before you can do anything.
Install Node.js® and npm if they are not already on your machine.
Install the Angular CLI globally
npm install -g @angular/cli
Get 1 back to main directory
/*Remove WordPress menu from admin bar*/
add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );
function remove_wp_logo( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'wp-logo' );
}
// Update WP login screen logo
function update_wp_logo_for_login_page() {
?>
<style type="text/css">
@developer-anuragsingh
developer-anuragsingh / WP - HTML Sitemap
Created April 12, 2018 07:03
Display HTML sitemap with shortcode 'html_sitemap'
// Display HTML SiteMap with shortcode "html_sitemap"
function as_display_html_sitemap( $pageArgArr ) {
if ( class_exists( 'WooCommerce' ) ) { // If woocommerce is activated, remove these pages
$pageToBeExclude = array('Cart', 'Checkout', 'Shipping Addresses', 'My Account', 'Payment', 'Thank you', 'Sitemap');
foreach ($pageToBeExclude as $page) {
$pageObj = get_page_by_title( $page );
$pageIdsTobeExclude[] = $pageObj->ID;
}