Skip to content

Instantly share code, notes, and snippets.

View Swapnildhanrale's full-sized avatar

Swapnil Ashok Dhanrale Swapnildhanrale

  • Brainstorm Force
  • Pune
View GitHub Profile
@Swapnildhanrale
Swapnildhanrale / functions.php
Created May 13, 2020 13:27
To display multiple category on product archive page
add_filter('astra_woo_shop_product_categories' , 'category_callback');
function category_callback(){
$product_categories = function_exists( 'wc_get_product_category_list' ) ? wc_get_product_category_list( get_the_ID(), ',', '', '' ) : $product->get_categories( ',', '', '' );
$categories = !empty( $product_categories ) ? $product_categories : '' ;
return $categories;
}
@Swapnildhanrale
Swapnildhanrale / Function.php
Created May 7, 2020 05:42
TO show all meta below post content on single and archive page
add_action('astra_entry_after', 'callback_function');
function callback_function(){
$enable_meta = apply_filters( 'astra_blog_post_meta_enabled', '__return_true' );
$post_meta = astra_get_option( 'blog-meta' );
if ( is_array( $post_meta ) && $enable_meta ) {
$output_str = astra_get_post_meta( $post_meta );
if ( ! empty( $output_str ) ) {
echo apply_filters( 'astra_blog_post_meta', '<div class="entry-meta">' . $output_str . '</div>', $output_str );
}
}
<?php
/**
* Add category above the title in Astra Theme
*
* @todo Change the `prefix_` and with your own unique prefix.
*
* @since 1.0.0
*/
if( ! function_exists( 'prefix_function_name' ) ) :
function prefix_function_name() {
@Swapnildhanrale
Swapnildhanrale / functions.php
Created November 25, 2019 06:08
Footer widget title tag change in Astra theme
// Footer Widget 1
add_filter( 'astra_advanced_footer_widget_1_args', 'widget_title_footer_1_tag', 10, 1 );
function widget_title_footer_1_tag( $atts ) {
$atts['before_title'] = '<h1 class="widget-title">';
$atts['after_title'] = '</h1>';
return $atts;
}
// Footer Widget 2
add_filter( 'astra_advanced_footer_widget_2_args', 'widget_title_footer_2_tag', 10, 1 );
function widget_title_footer_2_tag( $atts ) {
@Swapnildhanrale
Swapnildhanrale / functions.php
Created November 20, 2019 09:33
How to load astra fonts with Preload attribute
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 />
@Swapnildhanrale
Swapnildhanrale / Add category above the title in Astra Theme
Created August 20, 2019 05:28
Add category above the title in Astra Theme
<?php
/**
* Add category above the title in Astra Theme
*
* @todo Change the `prefix_` and with your own unique prefix.
*
* @since 1.0.0
*/
if( ! function_exists( 'prefix_function_name' ) ) :
@Swapnildhanrale
Swapnildhanrale / show-one-category.php
Created August 14, 2019 13:56
Show only one category from the the_category_list() function.
<?php
add_filter( 'the_category_list', function( $categories ) {
if( ! empty( $categories ) && is_array($categories) ) {
foreach ($categories as $key => $cat) {
if( ! $cat->parent ) {
$ob[] = $categories[$key];
return $ob;
}
}
}