Fix Spacing Issues in Gutenberg Blocks

Fix Spacing Issues in Gutenberg Blocks

Starter Templates plugin offers an option to import Gutenberg Templates and Blocks Patters. You can directly import templates inside the block editor.

Sometimes, after importing a template, you might observe some spacing or alignment changes compared to the original template you previewed before importing.

If you are experiencing some spacing differences after importing Gutenberg templates or block patterns, you can fix it quickly.

All you have to do is use a simple custom code.

Paste the following code in your child theme』s functions.php file.

add_filter( 'astra_gutenberg_patterns_compatibility', '__return_true' );

Note: If you are an existing Astra user and updating it from previous versions to v3.3, then only you will need this. If you start using Astra from version 3.3 and above you will not need to add this code.

Dim Content on Menu Hover

Dim Content on Menu Hover

Liked how the menu is styled on hover in the above GIF? You can add a similar dim effect to the content on the menu hover with the following CSS. With this, visitors will have an increased focus on the navigation menu and it』s better for conversion.

/* Dim content on menu hover */
#masthead:hover~#content {
opacity: 0.1;
transition: all 0.5s linear 0.1s;
}

#content {
transition: all 0.5s linear 0.1s;
}

Above CSS can be added to the customizer under Additional CSS tab or in the child theme』s style.css file.

How To Change Navigation Links Text for a Blog Archive?

How To Change Navigation Links Text for a Blog Archive?

Depending on your settings, your Blog Archive page might have multiple pages. In this case, the navigation links are being used to switch between different pages. These navigation links are displayed at the bottom of the page as 「Previous Page」 and 「Next Page」.

You can change these labels with any custom text 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_default_strings' , 'call_back');
function call_back( $default ){
$default['string-blog-navigation-previous'] = ' ' . __( 'Custom Previous Page', 'astra' );
$default['string-blog-navigation-next'] = __( 'Custom Next Page', 'astra' ) . ' ';
return $default;
}

This code will rename your navigation links to 「Custom Previous Page」 and 「Custom Next Page」. You can replace these link labels with any other text by modifying the bolded part of the code above.

If you don』t have your Child Theme installed, please check this article on how to do it. Also, If you are not sure how to add this code, please check this article.If you need to do modify navigational links on your Single Posts, please check out this document.

How To Enable Design Options for Header and Footer Widgets in Block-Based Editor

How To Enable Design Options for Header and Footer Widgets in Block-Based Editor

One of the many changes brought about by WordPress 5.8 is Block-Based Widgets Editor. This feature allowed using blocks in your widget areas, next to the older legacy widgets used before. Astra Theme provides support for this feature, including the Header and Footer Builder Widgets too. 

On the other hand, if you would like to continue using Astra』s widget design options for your Header and Footer widgets as before, you can do this by adding a code. This would allow you to keep using the theme widget design settings (font, color), together with the Block-Based Widgets Editor.

If on the other side you would like to completely remove the Block Editor support for Widgets, please check this article.

What Changed And Why Would I Need This?

The Astra theme provides a lot of freedom when building your websites. Header and Footer Widgets come with a number of different color and font settings making customization easy. 

With the introduction of Block-Based Widgets Editor, you can add Blocks directly to your Astra Header and Footer using the Widget Element. Since there are many Blocks, each with its own settings, we removed the Astra widget design options to fully support this WordPress feature.

Instead, you can customize each Block independently using its block editor settings. If you still wish to use Astra options for Header and Footer Widgets, you can do this by adding a filter. This will enable you to use Astra widget design options as before, while still fully benefiting from the improvements brought by Block-Based Widgets Editor.

You will find the needed Astra widget design options under the 「Design」 button of widget elements you add to your Header or Footer Builder.

How Can I Do This?

If you would like to enable Astra』s widget font and color options in Block-Based Widget Editor, you need to add a custom code. Please keep in mind that these design settings may not work for some widget blocks, as these options are deprecated. 

You can add the following custom code to the functions.php file of your Child Theme:

add_filter( 'astra_remove_widget_design_options', '__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.

How to Self-Host Google Fonts in Astra?

How to Self-Host Google Fonts in Astra?

Astra theme introduces a new feature called Self-Hosted Google Fonts available with the free theme version 3.6.0. This feature brings CLS and performance improvements by loading and saving the Google Fonts locally in the 「woff2」 format. You can navigate to Customizer > Performance and enable the 「Load Google Fonts Locally」 option to use the feature. Learn more about Self-Hosted Google Fonts in our Blog article.

Though the feature brings great improvements, you might need to make some modifications in specific situations, where you need to use different font file formats or in case you use Astra』s white-labeling feature.

This document will show you how to do these modifications easily.

How To Modify the Feature

One of the cases where you will need to modify the 「Self-Hosted Google Fonts」 feature is when the 「woff2」 font file format doesn』t suit your needs the best. For this reason, we added a filter to change the format of the font files, which will be locally saved. 

Also, this new feature creates a new local fonts folder and local fonts CSS file. Both have the Astra markings in their names which can be changed if you use the white-labeling feature. You can add a filter to remove Astra markings and assign the names as needed.

By using these filters, you will be able to make the mentioned changes on your website related to this feature while still benefiting from all the improvements it brings.

Before we move to the filters, it』s important to mention that it is advisable to have a Child Theme installed when adding any custom code to your website. If you need more details using a Child Theme check out this article. Also, we suggest you try doing this using a Staging environment and not your live (production) website directly.

How to Load Font File Formats Other Than 「woff2」?

Though the 「woff2」 comes with its advantages, it might not be a perfect fit for every website. 

The 「woff2」 format will work with around 96% of the currently used browsers. However, some browsers like Internet Explorer and Opera Mini do not support it. The solution for this is to load different font file formats.

In this case, you would just need to change the font file format to 「woff」, which is a supported format with these browsers. 

To change the font file format to 「woff」, please add the following filter to the functions.php file of your Child Theme:

// Load font formats other than "woff2"

add_filter( 'astra_local_google_fonts_format', 'update_astra_local_fonts_format' );
function update_astra_local_fonts_format( $font_format ) {
$font_format = 'woff'; // This will change format to "woff" - you can also use other format
return $font_format;
}

You can change the font file format to any other too using the same filter – just replace the 「woff」 with another format in this line of the filter code:

$font_format = 'woff'; // This will change format to "woff"

How to White-Label This Feature?

As mentioned, the 「Self-Hosted Google Fonts」 feature will create the font folder and local fonts CSS file, containing the traces of Astra affiliation in their names. If your clients inspect the website code or the website folders, they will be able to see the mentioned Astra markings (and not your own brand). 

If you wish to change the names of the font folder and/or local fonts CSS file, you can do this by adding the following two filters to the functions.php file of your Child Theme:

To rename the font folder name use this code:

// Update 'astra-local-fonts' directory name where font CSS will be located.

add_filter( 'astra_local_fonts_directory_name', 'update_astra_local_fonts_file_directory_name' );
function update_astra_local_fonts_file_directory_name( $folder_name ) {
$folder_name = 'mysite'; // So finally your local font directory name will be 'mysite'.
return $folder_name;
}

To rename the local fonts CSS file name use this code:

// Update 'astra-local-fonts.css' file name.

add_filter( 'astra_local_font_file_name', 'update_astra_local_fonts_file_name' );
function update_astra_local_fonts_file_name( $file_name ) {
$file_name = 'mysite-font'; // So finally your local font file name will be 'mysite-font.css'.
return $file_name;
}

Once you added the codes, please navigate to Customizer > Performance and flush the local fonts cache by clicking on the 「Flush Local Font Files」 button. This will make the effects of the above-mentioned codes immediately visible.

How to Fix Font-Weight Not Applying To Widget Titles?

How to Fix Font-Weight Not Applying To Widget Titles?

Previously, font-weight for widgets (all sidebar, footer, header) titles was applied only as 「normal」 no matter the weight set for the headings, even though this is a heading pattern.

With Astra Theme update 3.6.0, this issue was fixed, and now the heading settings are being appropriately applied to widget titles too.

If this improvement is not applied automatically to your website, this document will help you fix this.

Why Do I Need This Improvement?

So far, if you wanted to set your widget titles weight, you needed to add some custom CSS for this. 

Now this can be done from Customizer (Global Settings > Typography > Headings) by setting the weight for the appropriate heading type with these improvements. 

How To Fix This?

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

For the old users, this improvement needs to be activated by adding a filter. This was done to avoid any potential issues with existing websites, which could have appeared in some cases if these improvements would have been applied automatically. 

To apply the improvement to your existing website, you would need to add a filter to the functions.php file of your Child Theme. If you don』t have your Child Theme installed, please check this article on how to do it. Please add the following filter:

add_filter( 'astra_heading_fonts_typo_support', '__return_true' );

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

How to Add Custom CSS Code Without Editing Theme Files?

How to Add Custom CSS Code Without Editing Theme Files?

Sometimes you may find yourself needing to add Custom CSS in your WordPress site. There are easier ways to add CSS on your site. In this article, we will show you how to add custom CSS to your WordPress site without editing any theme files.

In Customizer

Since WordPress 4.7, users can now add custom CSS directly inside the Customizer which you can find in Customize → Additional CSS. This is super-easy and you would be able to see your changes with a live preview instantly.

It should be noted that the CSS added in this area is theme-specific, so if you switch themes, you』ll lose your CSS.

Using external plugin

Use the external plugin like Simple Custom CSS to add custom CSS.

Using a Child Theme

If you』re already using a child theme, you can use the style.css file to add your custom CSS. Read How to edit style.css in the child theme?

How to Display 「Last Updated」 instead of 「Published」 Date

How to Display 「Last Updated」 instead of 「Published」 Date

Astra by default displays the date when a post was published to your website visitors. Plus it adds the date when the post was last updated in the code – for SEO and Schema Markup.

Published date is displayed in the front end

Both, published as well as updated dates are available in the markup.

If you want to display last updated date for the post to your visitors, use the following custom code –

/**
* Display only last modified date in the post metadata.
*
* @param String $output Markup for the last modified date.
* @return void
*/
function your_prefix_post_date( $output ) {
$output = '';
$format = apply_filters( 'astra_post_date_format', '' );
$modified_date = esc_html( get_the_modified_date( $format ) );
$modified_on = sprintf(
esc_html( '%s' ),
$modified_date
);
$output .= '';
$output .= ' ' . $modified_on . '';
$output .= '';
return $output;
}
add_filter( 'astra_post_date', 'your_prefix_post_date' );

It hides the published date and makes updated date visible.

Note:

Add the above code into the child theme』s functions.php file.

How To Remove the Astra Header From Entire Site?

How To Remove the Astra Header From Entire Site?

Using the Astra Meta Settings, you can easily disable the Header for each page or post separately. On the other side, if you want to remove the Astra Header from your entire website, this could be a tedious and time-consuming task.

To completely remove the Astra Header in a quick and easy way, you can use a custom code (filter). You would need to add the following filter to the functions.php file of your Child Theme:

add_action( 'wp', 'remove_astra_header_callback');
function remove_astra_header_callback(){
remove_action( 'astra_header', 'astra_header_markup' );
}

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.

How to Add Custom PHP Code?

How to Add Custom PHP Code?

In many cases, you will need to add custom PHP code in the theme. In this article, let us explain some ways how you can do so:

1. Custom Layouts module in Astra Pro (Easiest)

Astra Pro Addon is a premium plugin that extends features of Astra theme. If you have purchased Astra Pro Addon, use the Custom Layouts module to add custom PHP code. Below are the steps that show how to add code –

Activate the Custom Layouts module from Astra Pro.Insert the code in the Code Editor.Select Hooks layout and choose the appropriate action / wp_head action.Choose to display it on the Entire WebsitePublish the layout.

Here is an example that shows how to add Google Analytics code. Similarly, you can add any custom code.

2. With Third-Party Plugin

There are free plugins available on WordPress Repository that you can use to add custom PHP code. Below are two of them:

Code SnippetsMy Custom Functions

3. In Child Theme

You can add a filter or custom PHP code through the WordPress Dashboard, follow the steps on how you can do the same –

Step 1: Install and Activate the Astra Child Theme from the WordPress Dashboard > Appearance > Themes > Astra Child Theme.

Step 2: Open the Theme Editor under the Appearance. Not seeing Theme Editor, troubleshoot the same.

Step 3: Navigate to the child theme』s functions.php, from the right-hand section and select functions.php.

Step 4: Add your code at the bottom of the file and click on Update File at the bottom.

Note: If you have the Parent theme active and visit the Theme Editor, you will see the following message, which informs you about how directly editing your theme could crash your website. Click on 「I understand」. 

Or if you have access to cPanel of your website, you can use FTP software like FileZilla. Below are the steps that explain how to do so –

Step 1: Install and activate the Astra Child Theme from the WordPress Dashboard.

Step 2: Open your WordPress site via FTP. We would recommend you to use FileZilla.

Step 3: Navigate to wp-content > themes > astra-child

Step 4: Right-click functions.php and select View/Edit

Step 5: Add your code at the bottom of the file and save it.