Filters to Support CPTs for Blog Meta and Single Blog Meta

Filters to Support CPTs for Blog Meta and Single Blog Meta

You can add the following filters to insert Blog Meta and Single Blog Meta to the Custom Post Types ( CPTs ) in the child theme』s functions.php –-

/*
* Filters to support meta-structure for CPT Single Posts & Archive
*/

add_filter( 'astra_blog_archive_post_type_meta', 'astra_blog_archive_post_type_meta_func' );

function astra_blog_archive_post_type_meta_func( $post_type_array ) {
array_push( $post_type_array, 'movies' ); //Here movies is the slug of CPT, you will need to update with the respective slug of your CPT
return $post_type_array;
}

add_filter( 'astra_single_post_type_meta', 'astra_single_post_type_meta_func' );

function astra_single_post_type_meta_func( $post_type_array ) {
array_push( $post_type_array, 'movies' ); //Here movies is the slug of CPT, you will need to update with the respective slug of your CPT
return $post_type_array;
}

Note

Refer this doc on How to Add Custom PHP Code?

How To Hide Quantity Number When the Woocommerce Cart Is Empty?

How To Hide Quantity Number When the Woocommerce Cart Is Empty?

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. 

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.

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.

Change the Astra Header Breakpoint Width

Change the Astra Header Breakpoint Width

In Astra Theme you can modify the screen size when you want to trigger the mobile header using the filter astra_header_break_point The default breakpoint is 921px. That means the mobile header will be triggered at 921px screen size.

Note:

If you are using {Astra』s Header Footer Builder} the below filter will not work, but to change the breakpoint you can go with updating tablet breakpoint as mentioned in this article. [Link here]

To change the default breakpoint use filter. In the below example the mobile header will be triggered at 1120px screen size. Change 1120 to the screen size of your choice.

/**
* Change the breakpoint of the Astra Header Menus
*
* @return int Screen width when the header should change to the mobile header.
*/
function your_prefix_change_header_breakpoint() {
return 1120;
};

add_filter( 'astra_header_break_point', 'your_prefix_change_header_breakpoint' );

Check out the doc that explains how to add custom PHP code using the child theme』s functions.php file. 

Note:

Astra version 1.4.0 and above provides an option to change the breakpoint. You don』t have to use the above filter. Refer to the document here.Further, after Astra 3.0.0 in the Astra』s Header Footer builder, we have provided a Mobile header that can be added for the Mobile devices. [Learn More]

Change the String 「Search Results For」

Change the String 「Search Results For」

When you execute a search within a website using Astra』s search option, you can see a similar layout as below. In case you wish to alter the default string – 」 Search Results For 「, use the code mentioned below.

Note: Add the following code in the child theme』s functions.php file.

add_filter( 'astra_the_search_page_title', 'my_function', 10 );

function my_function() {
return sprintf( __( 'Add Custom Text Here: %s', 'astra' ), '' . get_search_query() . '' );
}

Change Sidebar Widget Title Heading Tag

Change Sidebar Widget Title Heading Tag

When you add a widget in the sidebar, a default heading tag that will be applied to widget title is H2

If you wish to change this heading tag use the following custom code. Add the code in the child theme』s functions.php file. 

add_filter( 'astra_widgets_init', 'widget_title_tag', 10, 1 );

function widget_title_tag( $atts ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';

return $atts;
}

In the above code H2 heading tag is changed to H4. You can enter the required heading tag as per your requirement.

Change Footer Widget Title』s Heading Tag

Change Footer Widget Title』s Heading Tag

When you add a widget in the footer, a default heading tag that will be applied to widget title is H2

If you wish to change this heading tag use the following custom code. Add the respective filter code in the child theme』s functions.php file. 

// 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'] = '

';
$atts['after_title'] = '

';
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 ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';
return $atts;
}

// Footer Widget 3
add_filter( 'astra_advanced_footer_widget_3_args', 'widget_title_footer_3_tag', 10, 1 );

function widget_title_footer_3_tag( $atts ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';
return $atts;
}

// Footer Widget 4
add_filter( 'astra_advanced_footer_widget_4_args', 'widget_title_footer_4_tag', 10, 1 );

function widget_title_footer_4_tag( $atts ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';
return $atts;
}

// Footer Widget 5
add_filter( 'astra_advanced_footer_widget_5_args', 'widget_title_footer_5_tag', 10, 1 );

function widget_title_footer_5_tag( $atts ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';
return $atts;
}

You can choose from the required filter for the respective widget and update the tag as per your requirement.

For e.g. You are looking to update the Third Footer widget title for that you will need to copy the code just as below and paste it in your child theme』s functions.php.

add_filter( 'astra_advanced_footer_widget_3_args', 'widget_title_footer_3_tag', 10, 1 );

function widget_title_footer_3_tag( $atts ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';
return $atts;
}

Note:

If you have built the Footer using the Footer builder of Header Footer builder, please use the below code –

add_filter( 'astra_footer_widget_1args', 'widget_title_footer_1_tag', 10, 1 );

function widget_title_footer_1_tag( $atts ) {
$atts['before_title'] = '

';
$atts['after_title'] = '

';
return $atts;
}

Note:

Please note, that you pick the correct filter having the number and update the heading tags h4 or other as required.Refer this doc on How to Add Custom PHP Code?

Filter to Add Global Button Settings Support for WooCommerce Buttons

Filter to Add Global Button Settings Support for WooCommerce Buttons

Are you looking to add Global Button Settings Support for the WooCommerce Buttons? Now with the Astra Theme version 2.5.0, will be resolved –

For New Users:

On your fresh or new installations, compatibility of Global Button Settings will be provided for the WooCommerce Buttons by default.

For Existing Users:

You can use the following filter in the child theme』s functions.php to provide Global Button』s Support for the WooCommerce buttons.

add_filter( 'astra_global_btn_woo_comp' , '__return_true' );

Note

Refer this doc on How to Add Custom PHP Code?

Remove Primary Navigation Menu with Hook

Remove Primary Navigation Menu with Hook

Description

To remove Primary Navigation Menu, you can add the following PHP code –

remove_action( 'astra_masthead_toggle_buttons', 'astra_masthead_toggle_buttons_primary' );
remove_action( 'astra_masthead_content', 'astra_primary_navigation_markup', 10 );

Example

function remove_primary_menu_callback() {
remove_action( 'astra_masthead_toggle_buttons', 'astra_masthead_toggle_buttons_primary' );
remove_action( 'astra_masthead_content', 'astra_primary_navigation_markup', 10 );
}
add_action( 'init', 'remove_primary_menu_callback' );

Check out the doc that explains how to add custom PHP code using the child theme』s functions.php file.

Change Placeholder for Search Box (Old Astra Header)

Change Placeholder for Search Box (Old Astra Header)

Using the Astra Theme with old header options (Header Footer Builder is available since Astra theme version 3.0) and Astra Pro Addon, you can add a search box to your Primary Menu. The placeholder that is used here is 「Search」 by default.

You can change it to any text by adding a custom code. To do this, please add the following code to your Astra Child theme』s functions.php file:

function astra_get_search_form( $echo = true ) {

$form = '



';

// Replace My Placeholder with your desired string.

$result = apply_filters( 'astra_get_search_form', $form );

if ( null === $result ) {
$result = $form;
}

if ( $echo ) {
echo $result;
} else {
return $result;
}
}

To set your desired placeholder text, just replace the words My custom text with your text in the following part of the code:

...

...

In case you are using Astra Search Shortcodes, or you added the search feature to your Above or Below Header, the code will work only with the 「Slide」 search style.If you need to change the placeholder with other Search styles, please add one of these codes instead. Add the code based on the style you want to use:

for 「Full-Screen」 Style:

function full_screen_search_placeholder( $strings ) {
$strings['string-full-width-search-placeholder'] = 'My custom text';
return $strings;
}
add_filter( 'astra_default_strings', 'full_screen_search_placeholder', 99 );

for 「Header Cover」 Style:

function header_cover_search_placeholder( $strings ) {
$strings['string-header-cover-search-placeholder'] = 'My custom text';
return $strings;
}
add_filter( 'astra_default_strings', 'header_cover_search_placeholder', 99 );

for 「Search Box」 Style:

function search_box_placebolder( $form ) {
$form = str_replace( 'placeholder="Search …"', 'placeholder="My custom text"', $form );
return $form;
}
add_filter( 'astra_get_search_form', 'search_box_placebolder' );

Same as with the first code, to set your desired placeholder text, just replace the words My custom text with your text in the bolded part of the code.

Modify font-display Property Value

Modify font-display Property Value

The font-display CSS property defines how font files are loaded and displayed by the browser. Read an informative article by CSS-TRICKS here.

You can modify the value for this property using the following filter

add_filter( 'astra_fonts_display_property', 'astra_replace_fallback_with_swap' );
function astra_replace_fallback_with_swap( $property ) {
$property = 'swap';
return $property;
}

Note: Add above code to child theme』s functions.php file.

To check the font-display property, you can go to a page and press Ctrl+U OR Right-click > View Page Source.