How to Change the Default Astra Strings

How to Change the Default Astra Strings

Description

The astra_default_strings filter allows you to change the default strings printed by Astra.

Usage

// Filter callback function
function example_callback( $strings ) {
# ...
return $strings;
}
add_filter( 'astra_default_strings', 'example_callback', 10 );

Parameters

// 404 Page Strings
$strings['string-404-sub-title'] = __( 'This page doesn't seem to exist.', 'astra' );
$strings['string-404-search-title'] = __( 'It looks like the link pointing here was faulty. May be try searching?', 'astra' );

// Search Page Strings
$strings['string-search-nothing-found'] = __( 'Nothing Found', 'astra' );
$strings['string-search-nothing-found-message'] = __( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'astra' );
$strings['string-full-width-search-message'] = __( 'Start typing and press enter to search', 'astra' );
$strings['string-full-width-search-placeholder'] = __( 'Start Typing...', 'astra' );
$strings['string-header-cover-search-placeholder'] = __( 'Start Typing...', 'astra' );
$strings['string-search-input-placeholder'] = __( 'Search ...', 'astra' );

// Comment Template Strings
$strings['string-comment-reply-link'] = __( 'REPLY', 'astra' );
$strings['string-comment-edit-link'] = __( 'EDIT', 'astra' );
$strings['string-comment-awaiting-moderation'] = __( 'Your comment is awaiting moderation.', 'astra' );
$strings['string-comment-title-reply'] = __( 'Leave Comment', 'astra' );
$strings['string-comment-cancel-reply-link'] = __( 'Cancel Reply', 'astra' );
$strings['string-comment-label-submit'] = __( 'Post Comment →', 'astra' );
$strings['string-comment-label-message'] = __( 'Message', 'astra' );
$strings['string-comment-label-name'] = __( 'Name*', 'astra' );
$strings['string-comment-label-email'] = __( 'Email*', 'astra' );
$strings['string-comment-label-website'] = __( 'Website', 'astra' );
$strings['string-comment-closed'] = __( 'Comments are closed.', 'astra' );
$strings['string-comment-navigation-title'] = __( 'Comment navigation', 'astra' );
$strings['string-comment-navigation-next'] = __( 'Newer Comments', 'astra' );
$strings['string-comment-navigation-previous'] = __( 'Older Comments', 'astra' );
$strings['string-comment-one-comment'] = __( 'ONE COMMENT', 'astra' );
$strings['string-comment-multiple-comment'] = __( '%1$s COMMENTS', 'astra' );

// Blog Default Strings
$strings['string-blog-page-links-before'] = __( 'Pages:', 'astra' );
$strings['string-blog-meta-author-by'] = __( 'By ', 'astra' );
$strings['string-blog-meta-leave-a-comment'] = __( 'Leave a comment', 'astra' );
$strings['string-blog-meta-one-comment'] = __( '1 Comment', 'astra' );
$strings['string-blog-meta-multiple-comment'] = __( '% Comments', 'astra' );
$strings['string-blog-navigation-next'] = __('Next Page', 'astra') . ' →';
$strings['string-blog-navigation-previous'] = '← ' . __('Previous Page', 'astra');

// Single Post Default Strings
$strings['string-single-page-links-before'] = __( 'Pages:', 'astra' );
$strings['string-single-navigation-next'] = __('Next Post', 'astra') . ' →';
$strings['string-single-navigation-previous'] = '← ' . __('Previous Post', 'astra');

// Content None
$strings['string-content-nothing-found-message'] = __( 'It seems we can't find what you're looking for. Perhaps searching can help.', 'astra' );

Example

/**
* Update Search Nothing Found String and Search Input Box Placeholder Strings
*
* @param array $strings List of default strings used in theme
* @return array $strings
*/
function default_strings_callback( $strings ) {
// Search nothing found string
$strings['string-search-nothing-found-message'] = __( 'Sorry, There is no Search Result found.', 'astra' );
// Search input box placeholder
$strings['string-search-input-placeholder'] = __( 'Search ...', 'astra' );
return $strings;
}
add_filter( 'astra_default_strings', 'default_strings_callback', 10 );

Check out the doc that explains how to add custom PHP code using the child theme』s functions.php 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.

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.

How to Modify/Change the Quick View text?

How to Modify/Change the Quick View text?

As a shop owner, you might want to change the Quick View text. In this article, we will be seeing how to change the Quick View text using a filter.

In our WooCommerce Addon, as you can see we have the option to display the Quick View text based on the position which you have selected from the Astra settings.

So below are the filter based on the position to change the Quick View text –

1] For 「On Image」 position, you can use the following filter –

/**
* Change Quick View text from the shop page (for on image button option)
*
*/

add_filter( 'astra_woo_add_quick_view_text_html', 'astra_woo_add_quick_view_text_html_func', 10, 3 );

function astra_woo_add_quick_view_text_html_func( $button, $label, $product_id ) {

global $product;
$product_id = $product->get_id();

$label = __( 'Buy Now', 'astra-addon' );
$button = '' . $label . '';

return $button;
}

Here』s how it would display Before and After using the above filter –

Before –

After –

2] For After Summary position, you can use the following filter –

/**
* Change Quick View text from the shop page (for after summary option)
*
*/

add_filter( 'astra_woo_add_quick_view_button_html', 'astra_woo_add_quick_view_button_html_func', 10, 3 );

function astra_woo_add_quick_view_button_html_func( $button, $label, $product_id ) {

global $product;
$product_id = $product->get_id();

$label = __( 'Buy Now', 'astra-addon' );
$button = '

';
$button .= '' . $label . '';
$button .= '

';

return $button;
}

Here』s how it would display Before and After using the above filter.

Before –

After –

Note:

1. The above filter will change the 「Quick View」 text to the 「Buy Now」 text. You can update it as per your requirement.2. Paste the above code in the child theme』s functions.php file.

Blog Featured Image Size Not Working / Error in Image Processing Library

Blog Featured Image Size Not Working / Error in Image Processing Library

Are you facing any of the following issues listed below? We tried finding the probable cause but this being a rare scenario we have provided a filter to disable the cause and resolve such issues.

Types of Issues / Errors for which this document is valid –

Class is not found – WP_Image_Editor_ImagickCall to undefined method WP_Image_Editor_Imagick::get_error_message()wp_options table is bloated with entries like this – wp_addon_database_migration_batch_4935ee10bd16fca38a7cb9a9f5904d

In the above cases, there might sometimes be a conflict with the specific servers. For such cases you can disable Image Processing from Astra using the below filter.

You can use the following filter in the child theme』s functions.php –

add_filter( 'astra_image_resizer', '__return_false' );

Note

Refer this doc on How to Add Custom PHP Code?

How to Disable Primary Header?

How to Disable Primary Header?

You can disable Astra Primary Header from the entire site by adding a filter code to the child theme』s functions.php file. 

If you』re using the Old (Legacy) Astra Header for your website, you can add the following code:

add_action( 'wp', 'astra_remove_header' );

function astra_remove_header() {
remove_action( 'astra_masthead', 'astra_masthead_primary_template' );
}

On the other side, if you』re using the new Header Footer Builder (or decided to switch to it from the Legacy Header), you will need to use a different code instead:

add_action( 'wp' , 'astra_remove_new_header' );

function astra_remove_new_header() {
remove_action( 'astra_primary_header', array( Astra_Builder_Header::get_instance(), 'primary_header' ) );
remove_action( 'astra_mobile_primary_header', array( Astra_Builder_Header::get_instance(), 'mobile_primary_header' ) );
}

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.

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 Change HTML tag for Site Title and Tagline?

How to Change HTML tag for Site Title and Tagline?

From Astra customizer settings ( Customize > Header > Site Identity > Site Tagline / Site Title ), you can add the Title or a Tagline for your site. A Site Title is the name of your side, and the tagline is a small catchy descriptive line for your site.

By default, the Title has Heading 1 tag

while tagline has paragraph tag

in HTML structure. You can change this tag to any other HTML tag using the following filters:

Change Tag For a Tagline

add_filter( 'astra_site_tagline_tag', 'astra_change_site_tagline_tag' );

/* Function to change tag of Site Tagline.
@param string $tag Default is p tag.
*/
function astra_change_site_tagline_tag( $tag ) {
$tag = 'h6';
return $tag;
}

Note:

1. Above filter will change tag to tag. You can update it as per your requirement.2. Paste the above code in the child theme』s functions.php file.

This is how your Default tag looks in your code:

And this is the change from

to

in your code after adding the Filter:

Change Tag For a Site Title

You can also replace the H1 tag for the Title with span tag using the below filter –

add_filter( 'astra_site_title_tag', 'astra_function_change_site_title' );

/**
* Function to replace h1 tag with span in site title.
*
* @param string $tag This contains the tag used for site titles.
* @return string
*/
function astra_function_change_site_title( $tag ) {
$tag = 'span';
return $tag;
}

Restrict Search Results to WooCommece Products Only

Restrict Search Results to WooCommece Products Only

By default, when visitors use the Search option on your website, the results will show posts, pages, products, etc. that fit the term searched.

If you』re running an online store, you might want to limit the search only to WooCommece products. This can help users find products faster and increase the conversion rate on your website.

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

add_filter( 'get_search_form', 'astra_get_search_form_callback' );
function astra_get_search_form_callback( $search_form ) {
$search_form = str_replace( '-1">', '-1"/>', $search_form );
return $search_form;
}

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.