Custom Code Snippets – Astra https://wpastra.com Fast, Lightweight & Customizable WordPress Theme for Any Website Mon, 18 Apr 2022 09:24:38 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.3 https://wpastra.com/wp-content/uploads/2020/01/favicon-astra2x.png Custom Code Snippets – Astra https://wpastra.com 32 32 How to Remove Google Fonts Suggestions in Astra Theme? https://wpastra.com/docs/remove-google-fonts-suggestions-in-astra-theme/ https://wpastra.com/docs/remove-google-fonts-suggestions-in-astra-theme/#respond Tue, 05 Apr 2022 02:51:31 +0000 https://wpastra.com/?post_type=docs&p=120715 How to Remove Google Fonts Suggestions in Astra Theme? Read More »

]]>
Astra theme comes with built-in Google Font Families. Astra’s build process automatically checks all Google Fonts and lists them in Customizer options.

How To Remove Google Fonts Suggestions?

To remove Google Fonts suggestions from the Customizer.

You can insert the following filter in your child theme’s functions.php file –

add_filter( 'astra_google_fonts', '__return_empty_array' );

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/remove-google-fonts-suggestions-in-astra-theme/feed/ 0
Move Related Posts Below Comments https://wpastra.com/docs/move-related-posts-below-comments/ https://wpastra.com/docs/move-related-posts-below-comments/#respond Thu, 03 Feb 2022 13:58:46 +0000 https://wpastra.com/?post_type=docs&p=117113 Move Related Posts Below Comments Read More »

]]>
With the Astra theme, you can display related posts on all your posts. This document will provide a custom code to move related posts below the comments section.

What Is The Result?

The related posts section is displayed below your post content by default. Also, it’s a great feature that helps your users find additional interesting content from the same category. But, at the same time, this means that your users might overlook the comments section before moving to a related post.

Related Posts

Thus, you might want to move this section below the comments section, allowing your user to first go through comments. Further, you can do this easily by adding a custom code to your website.

Related Posts Below Comments

How To Do This?

To disable Astra Global colours in Elementor, you need to add an action. You can add the following custom code to the functions.php file of your Child Theme:

# Move Related Posts Below Comments

add_action( 'astra_entry_before', function() {
	add_filter( 'astra_get_option_enable-related-posts', '__return_false' );
} );
add_action( 'astra_primary_content_bottom', function() {
	add_filter( 'astra_get_option_enable-related-posts', '__return_true' );
} );
add_action( 'astra_template_parts_content_top', 'action_to_update_related_post_markup', 1 );
function action_to_update_related_post_markup() {
	$related_post_markup_instance = new Astra_Related_Posts_Markup();
	add_action( 'comment_form_after', array( $related_post_markup_instance, 'astra_get_related_posts' ), 10 );
}

If you don’t have your Child Theme installed, please check this article on how to do it. 
If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/move-related-posts-below-comments/feed/ 0
Disable Astra Global Colors In Elementor https://wpastra.com/docs/disable-astra-global-colors-in-elementor/ https://wpastra.com/docs/disable-astra-global-colors-in-elementor/#respond Thu, 27 Jan 2022 08:24:40 +0000 https://wpastra.com/?post_type=docs&p=116765 Disable Astra Global Colors In Elementor Read More »

]]>
Astra theme comes with the Global Color Palette feature that allows you to control colors across your entire website. Now, you can add your brand colors to Astra global colors and use them anywhere, including the Elementor Global Colors. However, if you want to disable Astra colors in Elementor, you must add custom code.

Astra Global Colors In Elementor

When designing your website, you will notice that both Elemetor and Astra global colors will be available in color settings. 

Astra Colors In Elementor

Sometimes, this can be confusing. Also, you might want to limit user rolls with Elementor access to using only Elementor Global Colors.

Astra Colors Disabled In Elementor

How To Remove This?

To disable Astra global colors in Elementor, you need to add a filter. You can add the following custom code to the functions.php file of your Child Theme:

# Disable Astra Global Colors In Elementor

add_filter( 'astra_disable_global_colors_in_elementor', '__return_true' );

If you don’t have your Child Theme installed, please check this article on how to do it. 

If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/disable-astra-global-colors-in-elementor/feed/ 0
Remove Woocommerce Product Category Archive Title https://wpastra.com/docs/remove-woocommerce-category-archive-title/ https://wpastra.com/docs/remove-woocommerce-category-archive-title/#respond Fri, 21 Jan 2022 16:39:21 +0000 https://wpastra.com/?post_type=docs&p=116553 Remove Woocommerce Product Category Archive Title Read More »

]]>
When you click on the category of your WooCommerce product, you will be transferred to the archive page. The category archive page will contain all products that belong to this category. If you want to remove the category archive title on the page, this document will help you do it.

Remove the WooCommerce category archive title

How To Remove This?

To remove the category archive title, you must add a filter. You can add the following custom code to the functions.php file of your Child Theme:

# Remove Woocommerce Category Title from the product archive page

add_filter( 'woocommerce_show_page_title', 'remove_category_title_from_product_archive' );
function remove_category_title_from_product_archive( $title ) {
if ( is_product_category() ) {
$title = false;
}
return $title;
}

If you don’t have your Child Theme installed, please check this article on how to do it. 

If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/remove-woocommerce-category-archive-title/feed/ 0
Remove Astra Customization for WooCommerce https://wpastra.com/docs/remove-astra-customization-for-woocommerce/ https://wpastra.com/docs/remove-astra-customization-for-woocommerce/#respond Wed, 19 Jan 2022 15:57:54 +0000 https://wpastra.com/?post_type=docs&p=116477 Remove Astra Customization for WooCommerce Read More »

]]>
The Astra Theme comes with out-of-the-box customization options for the WooCommerce plugin. You can use these to customize the Shop, Cart, and Checkout Pages as well as Single Products. 

Contrary, to use the default WooCommerce pages and options for your website, you need to use custom code. Thus, you can learn how to do it with this document.

What Will be the Result?

Astra theme and Astra Pro addon both allow you to customize WooCommerce pages according to your needs and brand. 

WooCommerce Customizing

Further, these customization options are applied automatically to your online store as soon as you install Astra. At the same time, this will add additional Astra-related code. Also, you will notice additional settings in the customizer too. 

Now, adding the code from this document will revert your WooCommerce pages, code, and customizer to defaults. For example, you might need this for some 3rd-party plugins to work well or make your own customizations.

WooCommerce Removed Astra Options

How To Change This?

To remove Astra customization and revert WooCommerce to defaults, you’ll need to add a filter. You can add the following custom code to the functions.php file of your Child Theme:

add_filter( 'astra_enable_woocommerce_integration', '__return_false' );

If you don’t have your Child Theme installed, please check this article on how to do it. 
If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/remove-astra-customization-for-woocommerce/feed/ 0
Gutenberg Editor And Frontend UI Improvements With Astra (3.7.4) https://wpastra.com/docs/gutenberg-ui-improvements-with-astra/ https://wpastra.com/docs/gutenberg-ui-improvements-with-astra/#respond Fri, 08 Oct 2021 15:45:47 +0000 https://wpastra.com/?post_type=docs&p=105016 Gutenberg Editor And Frontend UI Improvements With Astra (3.7.4) Read More »

]]>
Astra Theme version 3.7.4 brought interesting Gutenberg UI improvements for both Block editor and frontend user interface. 

This document will show you the changes we added and how to apply these improvements when you update your theme to 3.7.4.

Gutenberg UI Improvements Overview

We added Gutenberg UI improvements to several blocks as well as the whole Block editor:

  • Block layouts
  • “Spacer” block;
  • “Pullquote” block;
  • “File” block;
  • Block edit controles;
  • Block selection in the editor.

Let’s check out some details for each improvement:

Block layouts

We added layout compatibility for multiple blocks. The block layout now provides the following options:

  • Default Layout – a default boxed layout;
  • Wide Layout – this layout will inherit the width of the container you set on your website;
  • Full-width Layout – this layout will go edge-to-edge of the screen.
Gutenberg Block Layouts

This layout is available for Group, Cover, Columns, Heading, and Media & Text blocks. This structure is available for these blocks even when they are nested. Check out this visual representation of improvement:

Block Layouts Improvement

This improvement works both for the block editor and front end.

Spacer Block

The Spacer blocks were previously hard to notice. You would notice this block only when you clicked on it. Otherwise, the block stayed almost hidden.

Old Spacer Block

We made the block improvements by adding a light background and by displaying its assigned height.

Gutenberg UI Improvements - Spacer Block

Pullquote Block

We added a quote icon for the Pullquote block both in the editor and in the front end. This is how the Pullquote Block looked like previously:

Old Pullquote Block

The improvements make the block more visible and emphasize that the block content is a quote.

Gutenberg UI Improvements - Pullquote Block

File Block

Previously the File block didn’t have Style support which was improved in the mentioned update.

Old File Block

The style support is now available in the editor and the front-end as well.

Gutenberg UI Improvements - File Block

Block Edit Controls

In previous versions, the block controls had a lighter color making them less visible.

Block Edit Controls

The block edit controls are more visible now, as we gave them a darker color.

Gutenberg UI Improvements - Block Controls

Block Selection

Before improvements, it was not easy to tell what space is some block taking and where to click to start editing it.

The improvement now allows you to see each block and its borders by simply hovering over it with a mouse.

How To Get These Impovements?

For all new websites, Gutenberg UI improvements will be applied automatically when the theme is updated. 

As these improvements can reflect on the front end, you’ll need to activate changes by adding a filter for existing websites. This way, you can check how these changes apply to your website and make any adjustments if needed. 

To apply the improvements to your website, add the following filter to the functions.php file of your Child Theme:

// Filter to enable Astra 3.7.4 Gutenberg UI improvements
add_filter( 'astra_get_option_improve-gb-editor-ui', '__return_true' );

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/gutenberg-ui-improvements-with-astra/feed/ 0
Replace Deprecated Astra Theme and Astra Pro Hooks https://wpastra.com/docs/deprecated-astra-hooks/ https://wpastra.com/docs/deprecated-astra-hooks/#respond Fri, 08 Oct 2021 11:58:24 +0000 https://wpastra.com/?post_type=docs&p=104951 Replace Deprecated Astra Theme and Astra Pro Hooks Read More »

]]>
Following Astra Theme 3.7.4 and Astra Pro 3.6.2 updates, we deprecated a significant number of functions, filters, and actions. Thus, some of the Astra hooks you might have added to your website should be updated.

Therefore, this document will help you replace these hooks on your website. Please use the lists below to update your code.

Deprecated Astra Hooks and Their Replacements

In short, further down, you will find lists of functions, filters, and actions. Accordingly, please update hooks if you added any filters, actions, or other functions to your website.

Astra Theme 3.7.4 and Astra Pro 3.6.2 versions are still compatible with old codes to avoid any issues. Although your website will still work well after the update, you should replace deprecated hooks with the replacements below.

Further, to help you with these updates, we added backend notifications:

Deprecated Astra Hooks Norification

Hence, you can do this by replacing deprecated hooks in your code with the replacements from the lists. This way, your website will remain fully functional and compatible with future updates.

Deprecated actionReplacement
astra_get_css_filesastra_addon_get_css_files
astra_get_css_filesastra_addon_get_js_files
astra_after_render_jsastra_addon_after_render_js
asta_register_admin_menu astra_register_admin_menu
Deprecated filterReplacement
astra_bb_render_content_by_idastra_addon_bb_render_content_by_id
astra_get_assets_uploads_dirastra_addon_get_assets_uploads_dir
astra_pro_show_brandingastra_addon_show_branding
astra_dynamic_cssastra_addon_dynamic_css
astra_add_css_fileastra_addon_add_css_file
astra_add_js_fileastra_addon_add_js_file
astra_add_dependent_js_fileastra_addon_add_dependent_js_file
astra_render_cssastra_addon_render_css
astra_render_jsastra_addon_render_js
astra_languages_directoryastra_addon_languages_directory
astra_ext_default_addonsastra_addon_ext_default_addons
astra_get_addonsastra_addon_get_addons
astra_ext_enabled_extensionsastra_addon_enabled_extensions
astra_custom_404_optionsastra_addon_custom_404_options
astra_cache_asset_query_varastra_addon_cache_asset_query_var
astra_cache_asset_typeastra_addon_cache_asset_type
astra_load_dynamic_css_inlineastra_addon_load_dynamic_css_inline
astra_flags_svgastra_addon_flags_svg
astra_display_on_listastra_addon_display_on_list
astra_location_rule_post_typesastra_addon_location_rule_post_types
astra_user_roles_listastra_addon_user_roles_list
astra_target_page_settingsastra_addon_target_page_settings
astra_get_display_posts_by_conditionsastra_addon_get_display_posts_by_conditions
astra_meta_args_post_by_conditionastra_addon_meta_args_post_by_condition
astra_pro_white_label_add_formastra_addon_white_label_add_form
ast_footer_bar_displayastra_footer_bar_display
ast_main_header_displayastra_main_header_display
secondary_submenu_border_classastra_secondary_submenu_border_class
gtn_image_group_css_compastra_gutenberg_image_group_style_support
ast_footer_sml_layoutastra_footer_sml_layout
primary_submenu_border_classastra_primary_submenu_border_class
Deprecated functionReplacement
astra_get_supported_posts                                      astra_addon_get_supported_posts
astra_rgba2hexastra_addon_rgba2hex
astra_check_is_hexastra_addon_check_is_hex
is_support_swap_mobile_below_header_sectionsastra_addon_swap_mobile_below_header_sections
is_astra_theme_3_5_0_versionastra_addon_check_theme_3_5_0_version
sticky_header_default_site_title_tagline_css_compastra_addon_sticky_site_title_tagline_css_comp
is_support_swap_mobile_above_header_sectionsastra_addon_support_swap_mobile_above_header_sections
astra_return_content_layout_page_builderastra_addon_return_content_layout_page_builder
astra_return_page_layout_no_sidebarastra_addon_return_page_layout_no_sidebar
astra_pro_is_emp_endpointastra_addon_is_amp_endpoint
is_astra_breadcrumb_trailastra_addon_is_breadcrumb_trail
astra_breadcrumb_shortcodeastra_addon_breadcrumb_shortcode
astra_get_templateastra_addon_get_template
astra_locate_templateastra_addon_locate_template
astra_ext_adv_search_dynamic_cssastra_addon_adv_search_dynamic_css
astra_ext_advanced_search_dynamic_cssastra_addon_advanced_search_dynamic_css
astra_ext_header_builder_sections_colors_dynamic_cssastra_addon_header_builder_sections_colors_dynamic_css
astra_ext_header_sections_colors_dynamic_cssastra_addon_header_sections_colors_dynamic_css
astra_ldrv3_dynamic_cssastra_addon_ldrv3_dynamic_css
astra_learndash_dynamic_cssastra_addon_learndash_dynamic_css
astra_ext_mobile_above_header_dynamic_cssastra_addon_mobile_above_header_dynamic_css
astra_ext_mobile_below_header_dynamic_cssastra_addon_mobile_below_header_dynamic_css
astra_ext_mobile_header_colors_background_dynamic_cssastra_addon_mobile_header_colors_background_dynamic_css
astra_ext_mobile_header_spacing_dynamic_cssastra_addon_mobile_header_spacing_dynamic_css
astra_ext_mobile_header_dynamic_cssastra_addon_mobile_header_dynamic_css
astra_ext_mega_menu_dynamic_cssastra_addon_mega_menu_dynamic_css
astra_ext_scroll_to_top_dynamic_cssastra_addon_scroll_to_top_dynamic_css
astra_ext_fb_button_dynamic_cssastra_addon_footer_button_dynamic_css
astra_fb_divider_dynamic_cssastra_addon_footer_divider_dynamic_css
astra_fb_lang_switcher_dynamic_cssastra_addon_footer_lang_switcher_dynamic_css
astra_footer_social_dynamic_cssastra_addon_footer_social_dynamic_css
astra_ext_hb_button_dynamic_cssastra_addon_header_button_dynamic_css
astra_hb_divider_dynamic_cssastra_addon_header_divider_dynamic_css
astra_hb_lang_switcher_dynamic_cssastra_addon_header_lang_switcher_dynamic_css
astra_ext_hb_menu_dynamic_cssastra_addon_header_menu_dynamic_css
astra_header_social_dynamic_cssastra_addon_header_social_dynamic_css
]]>
https://wpastra.com/docs/deprecated-astra-hooks/feed/ 0
Hide the Text by Setting the Font Size to Zero https://wpastra.com/docs/setting-font-size-to-zero/ https://wpastra.com/docs/setting-font-size-to-zero/#respond Wed, 06 Oct 2021 10:27:12 +0000 https://wpastra.com/?post_type=docs&p=104895 Hide the Text by Setting the Font Size to Zero Read More »

]]>
Designing your website to look and work perfectly on all screen sizes is more important now than ever. Sometimes it’s not so easy to do this. If sometimes you would like to hide some text or labels on any screen, you’ll be able to do this by setting font size to zero.

This document will help you do this with the Astra Theme.

Why Is This Important?

This improvement came with the Astra Theme 3.6.9 update. In earlier versions of the Astra Theme setting the font size to zero was not possible.

This will ultimately help you with responsive design.

How To Change This?

For all new websites, these changes will be applied automatically. 

For the existing websites, this improvement needs to be activated by adding a filter. This was done to allow you to check how these changes apply to your website and make any changes if needed. 

To enable this improvement, you need to add the following custom code (filter) to the functions.php file of your Child Theme:

add_filter( 'astra_zero_font_size_case', '__return_true' );

If you don’t have your Child Theme installed, please check this article on how to do it. 
If you are not sure how to add this code, please check this article.

]]>
https://wpastra.com/docs/setting-font-size-to-zero/feed/ 0
How To Hide Quantity Number When the Woocommerce Cart Is Empty? https://wpastra.com/docs/hide-quantity-when-cart-is-empty/ https://wpastra.com/docs/hide-quantity-when-cart-is-empty/#respond Mon, 06 Sep 2021 14:41:45 +0000 https://wpastra.com/?post_type=docs&p=103256 How To Hide Quantity Number When the Woocommerce Cart Is Empty? Read More »

]]>
Astra’s Header Footer Builder comes with the WooCommerce Cart element that allows you to add the mini-cart to your header. By default, the mini-cart displays a number of items added to the cart together with the icon.

The mini-cart will show the number “0” until the first product is added to the cart. 

WooCommerce Mini-Cart

In case you would like to hide this number, you can do it by adding a custom code (filter). Adding the filter will hide the number of products while the mini-cart is empty.

Filter to Hide the Quantity Number When Cart I Empty

To do this, you would need to add the following filter to the functions.php file of your Child Theme:

add_filter('astra_woo_header_cart_total', 'remove_cart_count');
function remove_cart_count( $default){
	if(0 == WC()->cart->get_cart_contents_count()){
		return false;
	}else{
		return $default;
	}
}

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article

]]>
https://wpastra.com/docs/hide-quantity-when-cart-is-empty/feed/ 0
How to Display the Post Category as a Related Posts Title? https://wpastra.com/docs/display-category-as-related-posts-title/ https://wpastra.com/docs/display-category-as-related-posts-title/#respond Sun, 05 Sep 2021 14:13:31 +0000 https://wpastra.com/?post_type=docs&p=103212 How to Display the Post Category as a Related Posts Title? Read More »

]]>
The Astra Theme comes with the Related Posts feature, which helps you engage your visitors for a longer time. This feature displays posts within the related category, suggesting that your visitors read more content related to their topic of interest. 

Astra Related Posts

Further, you might want to change the Related Posts section title and show the Post Category name instead. You can do this by adding a custom code (filter). 

To do this, you would need to add the following filter to the functions.php file of your Child Theme:

add_filter( 'astra_related_posts_title', 'astra_related_poat_title' );
function astra_related_poat_title() {
   return sprintf(
	'<div class="ast-related-posts-title-section"> <%1$s class="ast-related-posts-title"> %2$s </%1$s> </div>',
	'h2',// enter your custom string here
	esc_html__( get_the_category()[0]->name, 'astra' )
   );
}

Once the filter is added, the Related Posts section title will display the category name of the current post:

Filter to Display the Post Category as a Related Posts Title

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article

]]>
https://wpastra.com/docs/display-category-as-related-posts-title/feed/ 0