Skip to content

Instantly share code, notes, and snippets.

View ashucg's full-sized avatar
🎧
Focusing

Ashutosh Sharma ashucg

🎧
Focusing
  • Pinjore, India
  • 11:29 (UTC +05:30)
View GitHub Profile
@ashucg
ashucg / scrollTo.js
Created December 12, 2017 12:36
Scroll an element into view
/**
* Scroll an element into view
* @param {Integer} duration in ms
* @param {Object} options such as middle (boolean)
*/
Element.prototype.scrollTo = function(duration, options) {
if (typeof duration === 'undefined' || duration <= 0) {
duration = 1; // Minimum value that can be used
}
if (options === undefined) options = {
@ashucg
ashucg / .htaccess
Created December 12, 2017 12:18
htaccess redirect non-www to www and HTTP to HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
@ashucg
ashucg / FoundationMenu.php
Last active May 5, 2017 18:21
Foundation 6 Menu for WP extending Walker class
<?php
class FoundationMenu extends Walker_Nav_Menu
{
function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output )
{
$element->has_children = !empty( $children_elements[$element->ID] );
$element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
$element->classes[] = ( $element->has_children ) ? 'has-dropdown' : '';
parent:: display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
@ashucg
ashucg / similar_posts_widget.php
Created May 5, 2017 18:11
WP class to create custom widget for displaying similar posts
<?php
class similar_posts_widget extends WP_Widget
{
function __construct()
{
parent::__construct('similar_posts_widget', __('Similar Posts', 'custom-slug'), [
'description' => __('Display similar post', 'custom-slug'),
]);
}