Skip to content

Instantly share code, notes, and snippets.

View premanshup's full-sized avatar
🔺
Decode the code

Premanshu Pandey premanshup

🔺
Decode the code
View GitHub Profile
@premanshup
premanshup / functions.php
Created May 19, 2020 02:36
If no widget present in Astra Theme, remove the sidebar for WooCommerce archive pages. ( Shop, Product Taxonomy, Checkout, Cart, Account Page ) - Add this code in child theem.
add_action( 'wp', 'astra_woo_sidebar_layout' );
function astra_woo_sidebar_layout() {
if ( is_shop() || is_product_taxonomy() || is_checkout() || is_cart() || is_account_page() ) {
add_filter( 'astra_page_layout', 'astra_page_layout_woo_no_sidebar', 100 );
}
}
function astra_page_layout_woo_no_sidebar( $sidebar_layout ) {
@premanshup
premanshup / functions.php
Created May 4, 2020 13:55
Change LTR to RTL using code.
add_action( 'init', 'astra_set_direction' );
function astra_set_direction() {
global $wp_locale, $wp_styles;
$direction = 'rtl';
$wp_locale->text_direction = $direction;
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
$wp_styles = new WP_Styles();
}
$wp_styles->text_direction = $direction;
@premanshup
premanshup / functions.php
Created April 26, 2020 16:54
Add string before Date in meta data.
/**
* Add prefix to your Date String.
*
* @param string $output Markup date.
*
* @return void
*/
function your_prefix_post_date( $output ) {
$output = '';
@premanshup
premanshup / functions.php
Created April 22, 2020 15:20
No Sidebar width class in the Gutenberg Editor
/**
* Astra Gutenberg layout class
*
* @param string $classes
* @return string
*/
function astra_gutenberg_layout_class( $classes ) {
$screen = get_current_screen();
if( ! $screen->is_block_editor() )
return $classes;
@premanshup
premanshup / functions.php
Created April 15, 2020 15:42
Preload font with Light svg issue fix. Ensure text error resolve.
add_filter( 'astra_enable_default_fonts', 'temp_disable_astra_fonts' );
function temp_disable_astra_fonts( $load ) {
$load = false;
return $load;
}
add_action( 'wp_head', 'add_astra_fonts_preload', 1 );
function add_astra_fonts_preload() {
?>
<link rel="preload" href="<?php echo get_site_url(); ?>/wp-content/themes/astra/assets/fonts/astra.woff" as="font" crossorigin />
<link rel="preload" href="<?php echo get_site_url(); ?>/wp-content/themes/astra/assets/fonts/astra.ttf" as="font" crossorigin />
@premanshup
premanshup / astra-wp-cli.php
Created March 24, 2020 10:02
Astra WP CLI Plugin
<?php
/**
* Plugin Name: Astra WP CLI
* Plugin URI: https://www.yourwebsiteurl.com/
* Description: This is the very first plugin I ever created.
* Version: 1.0
* Author: Your Name Here
* Author URI: http://yourwebsiteurl.com/
**/
@premanshup
premanshup / astra-wp-cli.php
Created March 17, 2020 11:20
Delete Astra single option from multisites.
<?php
// Command - wp delete-astra-option delete --key={astra-settings key}
namespace DeleteAstraOption;
use WP_CLI, WP_CLI_Command;
if( class_exists( 'WP_CLI_Command' ) ) {
class Commands extends WP_CLI_Command {
public function delete( $args, $assoc_args ) {
$option_key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : false;
if( ! $option_key ) {
@premanshup
premanshup / functions.php
Created February 26, 2020 09:10
Last menu item - Button - Full width issue when menu is disabled.
add_action( 'wp', 'astra_open_submenu_below_header' );
function astra_open_submenu_below_header() {
add_filter( 'astra_get_option_submenu-below-header', '__return_true' );
}
@premanshup
premanshup / gist:ef7484ab0b4fb467a89171dec2004a51
Created January 24, 2020 09:06
Check typography addon active or not and load options according.
$customizer_data = get_option( 'astra-settings', array() );
$is_typo_addon_active = is_callable( 'Astra_Ext_Extension::is_active' ) ? Astra_Ext_Extension::is_active( 'typography' ) : false;
for ( $i = 1; $i < 7; $i++ ) {
if ( ( ( $i > 3 ) && ( true === $is_typo_addon_active ) ) || ( $i < 4 ) ) {
if ( isset( $theme_settings[ 'font-size-h' . $i ] ) && '' !== $theme_settings[ 'font-size-h' . $i ] ) {
$elementor_page_settings[ 'astra_sites_heading_' . $i . '_typography' ] = 'custom';
$elementor_page_settings[ 'astra_sites_heading_' . $i . '_font_size' ] = array(
'unit' => $theme_settings[ 'font-size-h' . $i ]['desktop-unit'],
@premanshup
premanshup / functions.php
Created January 14, 2020 14:56
Change Blog Grid from 3 to 2 for Search Page
add_action( 'wp', 'astra_search_grid_check', 15 );
function astra_search_grid_check() {
if( is_search() ) {
add_filter( 'astra_get_option_blog-grid', 'astra_change_grid_search_page', 15, 3 );
}
}
function astra_change_grid_search_page( $value, $option, $default ) {
$value = '2';