Skip to content

Instantly share code, notes, and snippets.

View patilvikasj's full-sized avatar
🎯
Focusing

Vikas Patil patilvikasj

🎯
Focusing
View GitHub Profile
@patilvikasj
patilvikasj / disable-cors.php
Created December 19, 2024 07:46
Disable CORS on WordPress site for specific URL
<?php
/**
* Plugin Name: Disable CORS for Specific URL
* Description: Disables CORS headers for a specific URL in WordPress.
* Author: Your Name
* Version: 1.0
*/
add_action('send_headers', function () {
// Get the current URL path
@patilvikasj
patilvikasj / worker.js
Last active September 26, 2023 14:40
Redirection using CloudFlare workers
const base = "https://example.com";
const statusCode = 301;
async function handleRequest(request) {
const url = new URL(request.url);
let { pathname } = url;
// Split the pathname into parts using '/'
var parts = pathname.split('/');
var firstPart = parts[1];
@patilvikasj
patilvikasj / wpbb_filters.php
Created June 8, 2020 10:06
Filters for support site
<?php
/* Important actions related to core functionality */
// to remove admin bar for non admin
add_action('init','remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('manage_options')) {
add_filter('show_admin_bar', '__return_false');
}
@patilvikasj
patilvikasj / delete_gravity_form_entries.php
Last active September 15, 2021 21:09
This will register a WP CLI command to delete Gravity form Entries
<?php
/**
* Plugin Name: WP CLI commands for deleting Gravity form entries.
* Plugin URI: https://brainstormforce.com
* Description: Register WP CLI command to delete Gravity form entries.
* Version: 0.0.1
* Author: Brainstorm Force
* Author URI: https://brainstormforce.com
* Text Domain: bsf
*/
@patilvikasj
patilvikasj / display_primary_cat_shop.php
Last active December 20, 2019 10:49
Display primary category on shop page
<?php // Do not include this line in your theme's functions.php.
add_filter( 'astra_woo_shop_product_categories', 'display_primary_category_on_shop', 10, 2 );
function display_primary_category_on_shop( $categories_html, $product_id ) {
$terms = get_the_terms( $product_id, 'product_cat' );
if( ! empty( $terms ) ) {
$primary_category = get_post_meta( $product_id, '_yoast_wpseo_primary_product_cat', true );
@patilvikasj
patilvikasj / disable_off_canvas.php
Created November 18, 2019 14:51
Disable off canvas filter on WooCommerce shop page
<?php // Do not add this line in your theme's functions.php
add_filter( 'astra_get_option_shop-off-canvas-trigger-type', function( $value ) {
if( function_exists( 'is_shop' ) && is_shop() ) {
return 'disable';
}
return $value;
@patilvikasj
patilvikasj / disable_pagination.php
Last active November 5, 2019 07:57
Disable previous and next post links on single post screen
<?php // Do not include this line in functions.php
add_filter( 'astra_single_post_navigation_enabled', '__return_false' );
@patilvikasj
patilvikasj / display_author_info.php
Created October 23, 2019 12:26
This function will display author name, bio and Gravtar when author has no posts.
<?php // do not include this line in functions.php
add_filter( 'the_author', function( $name ) {
$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
return $author->display_name;
} );
add_filter( 'get_the_author_description', function( $value, $user_id, $original_user_id ) {
$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
return $author->description;
<?php // Do not include this line in your functions.php
add_filter( 'astra_excerpt_type', 'ast_modify_excerpt_type' );
function ast_modify_excerpt_type( $excerpt_type ) {
$excerpt_type = astra_get_option( 'blog-post-content' );
return $excerpt_type;
}
@patilvikasj
patilvikasj / overwrite_blog_template.php
Last active October 16, 2019 15:28
This is custom snippet to overwrite blog template for category archive page.
<?php // Do not include this line in your functions.php file.
add_filter( 'astra_blog_template_name', function( $name ) {
// Replace `block` with your category slug.
if( is_category( 'block' ) ) {
return 'block';
}
// For category with slug "book". You need to add template file `blog-layout-book.php` file to get this work.