Skip to content

Instantly share code, notes, and snippets.

View Nikschavan's full-sized avatar
🎯
Focusing

Nikhil Nikschavan

🎯
Focusing
View GitHub Profile
@Nikschavan
Nikschavan / auto-update-plugin.php
Last active September 8, 2016 10:08
Automatically update WordPress plugins whenever updates are available
<?php
function auto_update_specific_plugins ( $update, $item ) {
// Array of plugin slugs to always auto-update
$plugins = array (
'bb-ultimate-addon',
);
if ( in_array( $item->slug, $plugins ) ) {
return true; // Always update plugins in this array
} else {
@Nikschavan
Nikschavan / user.php
Last active September 19, 2016 12:46
Add this file in `wp-content/mu-plugins/user.php` and just reload the site, a new user will be created with username and password used in the script below.
<?php
add_action( 'init', 'add_new_user' );
function add_new_user() {
$website = "http://example.com";
$userdata = array(
'user_login' => 'user_name',
'user_url' => $website,
'user_pass' => 'user_password',
<?php
/**
* Change the dynamic header for a particular page.
*
* @param String $header_id Page/Template ID of the header set from the options panel.
* @return String Page/Template ID of the header after manipulation.
*/
function bbhf_header_override( $header_id ) {
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
<description>Generally-applicable sniffs for WordPress plugins</description>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-"/>
<rule ref="WordPress-Core" />
<rule ref="WordPress-Docs" />
@Nikschavan
Nikschavan / ssl.conf.template
Created January 29, 2018 07:33
Nginx SSL Configuration for Let's Encrypt.
listen 443 http2 ssl;
ssl on;
ssl_certificate /etc/letsencrypt/live/<your-domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<your-domain>/privkey.pem;
@Nikschavan
Nikschavan / allow-html-tags-in-post-excerpt.php
Created February 27, 2018 06:38
Allow iframe in the WordPress post excerpt.
<?php // don't copy this line in your code.
function your_prefix_custom_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
//Retrieve the post content.
$text = get_the_content('');
//Delete all shortcode tags from the content.
@Nikschavan
Nikschavan / astra-single-post-navigation-same-category.php
Created March 13, 2018 11:33
Make single post navigation to get links for posts in same category - Astra theme - https://wpastra.com/
<?php
function your_prefix_single_post_navigation_same_category( $args ) {
$args[ 'in_same_term' ] = true;
return $args;
}
add_filter( 'astra_single_post_navigation', 'your_prefix_single_post_navigation_same_category' );
@Nikschavan
Nikschavan / astra-sidebar-before-content.css
Created April 2, 2018 10:14
Astra Theme - Move the sidebar before the content on mobile
@media (max-width: 768px) {
#primary {
order: 2;
}
#secondary {
order: 1;
}
.ast-container {
@Nikschavan
Nikschavan / astra-sidebar-before-content.css
Created April 2, 2018 10:14
Astra Theme - Move the sidebar before the content on mobile
@media (max-width: 768px) {
#primary {
order: 2;
}
#secondary {
order: 1;
}
.ast-container {
jQuery(document).on('ready', function(event) {
// Scroll smoothly to anchor
jQuery('a[href^="#"]').on('click', function(event) {
var target = jQuery(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
jQuery('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);