Blog Filters – Astra https://wpastra.com Fast, Lightweight & Customizable WordPress Theme for Any Website Mon, 28 Mar 2022 10:03:27 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.3 https://wpastra.com/wp-content/uploads/2020/01/favicon-astra2x.png Blog Filters – Astra https://wpastra.com 32 32 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
How To Change Navigation Links Text for a Blog Archive? https://wpastra.com/docs/replace-blog-archive-navigation-strings/ https://wpastra.com/docs/replace-blog-archive-navigation-strings/#respond Sun, 05 Sep 2021 11:31:22 +0000 https://wpastra.com/?post_type=docs&p=103203 How To Change Navigation Links Text for a Blog Archive? Read More »

]]>
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”.

Blog Archive Navigation Links

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'] = '<span class="ast-left-arrow">&larr;</span> ' . __( 'Custom Previous Page', 'astra' );
 $default['string-blog-navigation-next'] = __( 'Custom Next Page', 'astra' ) . ' <span class="ast-right-arrow">&rarr;</span>';
 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.

Filter To Change Navigation Links Text for a Blog Archive

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.

]]>
https://wpastra.com/docs/replace-blog-archive-navigation-strings/feed/ 0
Blog Featured Image Size Not Working / Error in Image Processing Library https://wpastra.com/docs/blog-featured-image-size-issues/ Tue, 28 Jul 2020 03:46:26 +0000 https://wpastra.com/?post_type=docs&p=59600 Blog Featured Image Size Not Working / Error in Image Processing Library Read More »

]]>
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 –

  1. Class is not found – WP_Image_Editor_Imagick
  2. Call to undefined method WP_Image_Editor_Imagick::get_error_message()
  3. 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?

]]>
Filters to Support CPTs for Blog Meta and Single Blog Meta https://wpastra.com/docs/add-blog-meta-support-cpts/ Tue, 28 Jul 2020 03:39:49 +0000 https://wpastra.com/?post_type=docs&p=61458 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?

]]>
Filter to Remove Link From Featured Images on Blog Page https://wpastra.com/docs/remove-featured-image-link-on-blog-page/ Wed, 12 Feb 2020 08:06:01 +0000 https://wpastra.com/?post_type=docs&p=55726 Filter to Remove Link From Featured Images on Blog Page Read More »

]]>
Do you see the default link on the Featured Image of the Posts on Blog Page?

Why?

The Featured Images added to each post are set a link to the same post.

How to clear?

From the Astra Theme version – 2.2.2 we providing a filter using which the link to the post can be removed.

Filter: The filter has been added to remove the featured image link on the blog page.

/**
  * Remove HTML before tag for link.
  * @param string $markup markup of post.
  * @return string
  */
function astra_remove_link_before( $markup ) {
    $markup = __return_empty_string();
    return $markup;
}

/**
  * Remove HTML after tag for link.
  * @param string $markup markup of post.
  * @return string
  */
function astra_remove_link_after( $markup ) {
    $markup = __return_empty_string();
    return $markup;
}

add_filter( 'astra_blog_post_featured_image_link_before', 'astra_remove_link_before' );
add_filter( 'astra_blog_post_featured_image_link_after', 'astra_remove_link_after' );

Note: Add the above filter to your child theme’s functions.php, here’s an article to help you Add Custom code.

]]>
How to Remove Featured Image Link on Archive Page? https://wpastra.com/docs/remove-featured-image-link-on-archive-page/ Fri, 13 Dec 2019 08:48:59 +0000 https://wpastra.com/?post_type=docs&p=50448 How to Remove Featured Image Link on Archive Page? Read More »

]]>
A Featured Image on the Archive pages has a link to the image, if you need to remove the link you will need to just use the following filters –

// Filter to remove featured image link on Archive Page

add_filter( 'astra_blog_post_featured_image_link_before', '__return_empty_string' );
add_filter( 'astra_blog_post_featured_image_link_after', '__return_empty_string' );

Note: Add the above filter to your child theme’s functions.php, here’s an article to help you Add Custom code.

]]>
How to Change Previous and Next Link Text from a Single Blog Post? https://wpastra.com/docs/replace-navigation-strings-on-single-post/ Mon, 22 Apr 2019 18:30:00 +0000 https://wpastra.com/?post_type=docs&p=31633 How to Change Previous and Next Link Text from a Single Blog Post? Read More »

]]>
Sometimes you might need to change the navigation (Previous and Next ) links to text on the single blog post. Default strings for navigation links will be – Previous Post and Next Post. You can change it using the following filters.

1. Replace default navigation strings with next/previous post titles

The following filter will fetch the Previous and Next post title and will display them as navigation links.

add_filter( 'astra_single_post_navigation', 'astra_change_next_prev_text' );

/**
 * Function to change the Next Post/ Previous post text.
 *
 * @param array $args Arguments for next post / previous post links.
 * @return array
 */
function astra_change_next_prev_text( $args ) {
	$next_post = get_next_post();
	$prev_post = get_previous_post();
	$next_text = false;
	if ( $next_post ) {
		$next_text = sprintf(
			'%s <span class="ast-right-arrow">→</span>',
			$next_post->post_title
		);
	}
	$prev_text = false;
	if ( $prev_post ) {
		$prev_text = sprintf(
			'<span class="ast-left-arrow">←</span> %s',
			$prev_post->post_title
		);
	}
	$args['next_text'] = $next_text;
	$args['prev_text'] = $prev_text;
	return $args;
}

2. Replace default navigation strings with custom text

The following filter will replace Previous and Next links with your custom text. You can replace your text with – ‘My Previous Custom Text’ and ‘My Next Custom Text’ in the following filter code.

Astra Navigate Text
add_filter( 'astra_single_post_navigation', 'astra_change_next_prev_text' );
 
/**
 * Function to change the Next Post/ Previous post text.
 *
 * @param array $args Arguments for next post / previous post links.
 * @return array
 */
function astra_change_next_prev_text( $args ) {
    $next_post = get_next_post();
    $prev_post = get_previous_post();
    $next_text = false;
    if ( $next_post ) {
        $next_text = sprintf(
            '%s <span class="ast-right-arrow">→</span>',
            'My Next Custom Text'
        );
    }
    $prev_text = false;
    if ( $prev_post ) {
        $prev_text = sprintf(
            '<span class="ast-left-arrow">←</span> %s',
            'My Previous Custom Text'
        );
    }
    $args['next_text'] = $next_text;
    $args['prev_text'] = $prev_text;
    return $args;
}

Note: Add the above code in the child theme’s functions.php file.

]]>
How to Display “Last Updated” instead of “Published” Date https://wpastra.com/docs/show-last-updated-not-published-date/ Thu, 03 May 2018 18:30:00 +0000 https://wpastra.com/?post_type=docs&p=26203 How to Display “Last Updated” instead of “Published” Date Read More »

]]>
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.

Astra Date Option

Published date is displayed in the front end

Date in Code Astra

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.

]]>