: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* Add classes to body tag */
add_filter( 'body_class', 'herald_body_class' );
if ( !function_exists( 'herald_body_class' ) ):
function herald_body_class( $classes ) {
if ( herald_get_option( 'content_layout' ) == 'boxed' ) {
$classes[] = 'herald-boxed';
$classes[] = 'herald-v_' . str_replace('.', '_', HERALD_THEME_VERSION);
if ( is_child_theme() ) {
$classes[] = 'herald-child';
/* Add media grabber features */
add_action( 'init', 'herald_add_media_grabber' );
if ( !function_exists( 'herald_add_media_grabber' ) ):
function herald_add_media_grabber() {
if ( !class_exists( 'Hybrid_Media_Grabber' ) ) {
include_once get_parent_theme_file_path( '/inc/media-grabber/class-hybrid-media-grabber.php' );
/* Add class to gallery images to run our pop-up and change sizes */
add_filter( 'shortcode_atts_gallery', 'herald_gallery_atts', 10, 3 );
if ( !function_exists( 'herald_gallery_atts' ) ):
function herald_gallery_atts( $output, $pairs, $atts ) {
if ( herald_get_option( 'popup_img' ) ) {
$output['link'] = 'file';
add_filter( 'wp_get_attachment_link', 'herald_add_class_attachment_link', 10, 1 );
if ( !isset( $output['columns'] ) ) {
if ( herald_get_option( 'auto_gallery_img_sizes' ) ) {
switch ( $output['columns'] ) {
case '1' : $output['size'] = 'herald-lay-a-full'; break;
case '2' : $output['size'] = 'herald-lay-a'; break;
case '3' : $output['size'] = 'herald-lay-c1'; break;
case '4' : $output['size'] = 'herald-lay-f1-full'; break;
case '6' : $output['size'] = 'herald-lay-f1'; break;
case '9' : $output['size'] = 'herald-lay-i1'; break;
default: $output['size'] = 'herald-lay-a-full'; break;
//Check if has a matched image size
global $herald_image_matches;
if ( !empty( $herald_image_matches ) && array_key_exists( $output['size'], $herald_image_matches ) ) {
$output['size'] = $herald_image_matches[$output['size']];
if ( !function_exists( 'herald_add_class_attachment_link' ) ):
function herald_add_class_attachment_link( $link ) {
$link = str_replace( '<a', '<a class="herald-popup"', $link );
* Filter Function to set replace gallery block with gallery shortocede
add_filter( 'the_content', 'herald_fallback_gallery_filter', 3 );
if ( !function_exists( 'herald_fallback_gallery_filter' ) ) :
function herald_fallback_gallery_filter( $content ) {
if ( !herald_get_option( 'auto_gallery_img_sizes' ) ) {
if(!function_exists('parse_blocks') ){
if ( empty( $content ) ) {
$content = $post->post_content;
$blocks = parse_blocks( $content );
if ( empty( $blocks ) ) {
foreach ( $blocks as $block ) {
if ( $block['blockName'] == 'core/gallery' && isset( $block['attrs']['columns'] ) && $block['attrs']['columns'] < 2 ) {
if ( isset( $block['attrs']['ids'] ) && !empty( $block['attrs']['ids'] ) ) {
$gallery_ids = $block['attrs']['ids'];
preg_match_all( '/data-id="(.*?)"/i', $content, $id_matches );
if ( empty( $id_matches[1] ) ) {
foreach ( $id_matches[1] as $match ) {
$pattern = '/<ul class="wp-block-gallery(.*?)<\/ul>/i';
$shortcode = '[gallery ids="' . implode( ',', $gallery_ids ) . '" columns="1"]';
$content = preg_replace( $pattern, $shortcode, $content, 1 );
/* Unregister Entry Views widget */
add_action( 'widgets_init', 'herald_unregister_widgets', 99 );
if ( !function_exists( 'herald_unregister_widgets' ) ):
function herald_unregister_widgets() {
$widgets = array( 'EV_Widget_Entry_Views' );
//Allow child themes or plugins to add/remove widgets they want to unregister
$widgets = apply_filters( 'herald_modify_unregister_widgets', $widgets );
if ( !empty( $widgets ) ) {
foreach ( $widgets as $widget ) {
unregister_widget( $widget );
/* Remove entry views support for other post types, we need post support only */
add_action( 'init', 'herald_remove_entry_views_support', 99 );
if ( !function_exists( 'herald_remove_entry_views_support' ) ):
function herald_remove_entry_views_support() {
$types = array( 'page', 'attachment', 'literature', 'portfolio_item', 'recipe', 'restaurant_item' );
//Allow child themes or plugins to modify entry views support
$widgets = apply_filters( 'herald_modify_entry_views_support', $types );
if ( !empty( $types ) ) {
foreach ( $types as $type ) {
remove_post_type_support( $type, 'entry-views' );
/* Prevent redirect issue that may brake home page pagination caused by some plugins */
add_filter( 'redirect_canonical', 'herald_disable_redirect_canonical' );
function herald_disable_redirect_canonical( $redirect_url ) {
if ( is_page_template( 'template-modules.php' ) && is_paged() ) {
/* Add span elements to post count number in category widget */
add_filter( 'wp_list_categories', 'herald_add_span_cat_count', 10, 2 );
if ( !function_exists( 'herald_add_span_cat_count' ) ):
function herald_add_span_cat_count( $links, $args ) {
if ( isset( $args['taxonomy'] ) && $args['taxonomy'] != 'category' ) {
$links = preg_replace( '/(<a[^>]*>)/', '$1<span class="category-text">', $links );
$links = str_replace( '</a>', '</span></a>', $links );
$links = str_replace( '</a> (', '<span class="count">', $links );
$links = str_replace( ')', '</span></a>', $links );
add_action( 'pre_get_posts', 'herald_pre_get_posts' );
if ( !function_exists( 'herald_pre_get_posts' ) ):
function herald_pre_get_posts( $query ) {
if ( !is_admin() && $query->is_main_query() && $query->is_archive() && !$query->is_feed()) {
$template = herald_detect_template();
/* Check whether to change number of posts per page for specific archive template */
$ppp = herald_get_option( $template.'_ppp' );
if ( $template == 'category' ) {
$obj = get_queried_object();
$cat_meta = herald_get_category_meta( $obj->term_id );
if ( $cat_meta['layout'] == 'inherit' || $cat_meta['ppp'] == 'inherit' ) {
if ( $ppp == 'custom' ) {
$ppp_num = absint( herald_get_option( $template.'_ppp_num' ) );
$query->set( 'posts_per_page', $ppp_num );
if ( $cat_meta['ppp'] == 'custom' ) {
$query->set( 'posts_per_page', $cat_meta['ppp_num'] );
if ( $ppp == 'custom' ) {
$ppp_num = absint( herald_get_option( $template.'_ppp_num' ) );
$query->set( 'posts_per_page', $ppp_num );
/* Check for featured area on category page and exclude those posts from main post listing */
if ( $template == 'category' ) {
$fa = herald_get_featured_area();
if ( !empty( $fa ) && herald_get_option( 'category_fa_unique' ) ) {
if ( isset( $fa['query'] ) && !is_wp_error( $fa['query'] ) && !empty( $fa['query'] ) ) {
foreach ( $fa['query']->posts as $p ) {
$query->set( 'post__not_in', $exclude_ids );
* Modify WooCommerce Wrappers
* Modify WooCommerce Wrappers according to Herald Structure
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
add_action( 'woocommerce_before_main_content', 'herald_woocommerce_wrapper_start', 10 );
add_action( 'woocommerce_after_main_content', 'herald_woocommerce_wrapper_end', 10 );
if ( !function_exists( 'herald_woocommerce_wrapper_start' ) ):
function herald_woocommerce_wrapper_start() {
global $herald_sidebar_opts;
$col_class = $herald_sidebar_opts['use_sidebar'] == 'none' ? 12 : 9;
$left_sid_mod_class = $herald_sidebar_opts['use_sidebar'] == 'left' ? 'herald-woo-mod-right' : '';
echo '<div class="herald-section container"><div class="row"><div class="herald-module herald-main-content '.$left_sid_mod_class.' col-lg-'.esc_attr( $col_class ).' col-md-'.esc_attr( $col_class ).'">';
if ( !function_exists( 'herald_woocommerce_wrapper_end' ) ):
function herald_woocommerce_wrapper_end() {
add_action( 'herald_before_end_content', 'herald_woocommerce_close_wrap' );
if ( !function_exists( 'herald_woocommerce_close_wrap' ) ):
function herald_woocommerce_close_wrap() {
if ( herald_is_woocommerce_active() && herald_is_woocommerce_page() ) {
* Woocommerce Cart Elements
if ( !function_exists( 'herald_woocommerce_cart_elements' ) ):
function herald_woocommerce_cart_elements() {
if( !herald_is_woocommerce_active() ){ return; }
$elements['cart_url'] = wc_get_cart_url();
$elements['products_count'] = WC()->cart->get_cart_contents_count();
* Woocommerce Ajaxify Cart
if ( !function_exists( 'herald_woocommerce_ajax_fragments' ) ):
if ( herald_is_woocommerce_active() && version_compare( WC_VERSION, '3.2.6', '<') ) {
add_filter( 'add_to_cart_fragments', 'herald_woocommerce_ajax_fragments' );
add_filter( 'woocommerce_add_to_cart_fragments', 'herald_woocommerce_ajax_fragments' );
function herald_woocommerce_ajax_fragments( $fragments ) {
$elements = herald_woocommerce_cart_elements();
<a class="herald-custom-cart fa fa-shopping-cart" href="<?php echo esc_url( $elements['cart_url'] ); ?>">
<?php if( $elements['products_count'] > 0 ) : ?>
<span class="herald-cart-count"><?php echo absint( $elements['products_count'] ); ?></span>
$fragments['a.herald-custom-cart'] = ob_get_clean();
* Support for WMPU Dev - Custom Sidebars Plugin
* If sidebar params are not entered in a plugin settings, it will inherit before and after params from our theme
* @return array of sidebar params
add_filter( 'cs_sidebar_params', 'herald_cs_sidebar_params' );
if ( !function_exists( 'herald_cs_sidebar_params' ) ):
function herald_cs_sidebar_params( $sidebar ) {
if ( empty( $sidebar['before_widget'] ) && empty( $sidebar['after_widget'] ) ) {
$sidebar['before_widget'] = '<div id="%1$s" class="widget %2$s">';
$sidebar['after_widget'] = '</div>';
if ( empty( $sidebar['before_title'] ) && empty( $sidebar['after_title'] ) ) {
$sidebar['before_title'] = '<h4 class="widget-title h6"><span>';
$sidebar['after_title'] = '</span></h4>';
* Filter Function to add class to linked media image for popup
add_filter( 'the_content', 'herald_popup_media_in_content', 100, 1 );
add_filter('bbp_get_topic_content','herald_popup_media_in_content');
add_filter('bbp_get_reply_content','herald_popup_media_in_content');
if ( !function_exists( 'herald_popup_media_in_content' ) ):
function herald_popup_media_in_content( $content ) {
if ( herald_get_option( 'on_single_img_popup' ) ) {
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")>/i";
$replacement = '<a$1class="herald-popup-img" href=$2$3.$4$5>';
$content = preg_replace( $pattern, $replacement, $content );
* Add comment form default fields args filter
* to replace comment fields labels
add_filter('comment_form_default_fields', 'herald_comment_fields_labels');
if(!function_exists('herald_comment_fields_labels')):
function herald_comment_fields_labels($fields){
'old' => esc_html__( 'Name', 'herald' ),
'new' =>__herald( 'comment_name' )
'old' => esc_html__( 'Email', 'herald' ),
'new' =>__herald( 'comment_email' )
'old' => esc_html__( 'Website', 'herald' ),
'new' =>__herald( 'comment_website' )
'old' => esc_html__( 'Save my name, email, and website in this browser for the next time I comment.', 'herald' ),
'new' =>__herald( 'comment_cookie_gdpr' )
foreach($fields as $key => $field){
if(array_key_exists($key, $replace)){
$fields[$key] = str_replace($replace[$key]['old'], $replace[$key]['new'], $fields[$key]);
* Filter for social share options on frontend in the_content filter
* @param array $options - Array of options
add_filter( 'meks_ess_modify_options', 'herald_social_share_modify_options' );
if ( !function_exists( 'herald_social_share_modify_options' ) ):