', esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'colormag_pingback_header' );
/**
* Removing the default style of WordPress gallery.
*/
add_filter( 'use_default_gallery_style', '__return_false' );
/**
* Filtering the size to be full from thumbnail to be used in WordPress gallery as a default size.
*
* @param array $out The output array of shortcode attributes.
* @param array $pairs The supported attributes and their defaults.
* @param array $atts The user defined shortcode attributes.
*
* @return mixed
*/
function colormag_gallery_atts( $out, $pairs, $atts ) {
$atts = shortcode_atts(
array(
'size' => 'colormag-featured-image',
),
$atts
);
$out['size'] = $atts['size'];
return $out;
}
add_filter( 'shortcode_atts_gallery', 'colormag_gallery_atts', 10, 3 );
/**
* Removing the more link jumping to middle of content.
*
* @param string $link Read More link element.
*
* @return string|string[]
*/
function colormag_remove_more_jump_link( $link ) {
$offset = strpos( $link, '#more-' );
if ( $offset ) {
$end = strpos( $link, '"', $offset );
}
if ( $end ) {
$link = substr_replace( $link, '', $offset, $end - $offset );
}
return $link;
}
add_filter( 'the_content_more_link', 'colormag_remove_more_jump_link' );
/**
* Creating responsive video for posts/pages.
*
* @param string|false $html The cached HTML result, stored in post meta.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param int $post_ID Post ID.
*
* @return string
*/
function colormag_responsive_video( $html, $url, $attr, $post_ID ) {
if ( ! current_theme_supports( 'responsive-embeds' ) ) {
return '
' . $html . '
';
}
return $html;
}
add_filter( 'embed_oembed_html', 'colormag_responsive_video', 10, 4 );
/**
* Use of the hooks for Category Color in the archive titles
*
* @param string $title Category title.
*
* @return string Category page title.
*/
function colormag_colored_category_title( $title ) {
$output = '';
$color_value = colormag_category_color( get_cat_id( $title ) );
$color_border_value = colormag_category_color( get_cat_id( $title ) );
if ( ! empty( $color_value ) ) {
$output = '' . esc_html( $title ) . '
';
} else {
$output = '' . $title . '
';
}
return $output;
}
/**
* Filters the single_cat_title.
*
* @param string $category_title Category title.
*/
function colormag_category_title_function( $category_title ) {
add_filter( 'single_cat_title', 'colormag_colored_category_title' );
}
add_action( 'colormag_category_title', 'colormag_category_title_function' );
/**
* Filter the get_header_image_tag() for option of adding the link back to home page option.
*
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
*
* @return string
*/
function colormag_header_image_markup( $html, $header, $attr ) {
$output = '';
$header_image = get_header_image();
if ( ! empty( $header_image ) ) {
$output .= '';
}
return $output;
}
add_filter( 'get_header_image_tag', 'colormag_header_image_markup', 10, 3 );
/**
* Filter the body_class.
*
* Throwing different body class for the different layouts in the body tag.
*
* @param array $classes CSS classes applied to the body tag.
*
* @return array Classes for body.
*/
function colormag_body_class( $classes ) {
global $post;
if ( $post ) {
$layout_meta = get_post_meta( $post->ID, 'colormag_page_layout', true );
}
if ( is_home() ) {
$queried_id = get_option( 'page_for_posts' );
$layout_meta = get_post_meta( $queried_id, 'colormag_page_layout', true );
}
if ( empty( $layout_meta ) || is_archive() || is_search() ) {
$layout_meta = 'default_layout';
}
$woocommerce_widgets_enabled = get_theme_mod( 'colormag_woocommerce_sidebar_register_setting', 0 );
$colormag_default_sidebar_layout = get_theme_mod( 'colormag_default_sidebar_layout', 'right_sidebar' );
$colormag_page_sidebar_layout = get_theme_mod( 'colormag_page_sidebar_layout', 'right_sidebar' );
$colormag_default_post_layout = get_theme_mod( 'colormag_post_sidebar_layout', 'right_sidebar' );
/**
* Header styles.
*/
$header_layout_class = get_theme_mod( 'colormag_main_header_layout', 'layout-1' );
if ( 'layout-1' === $header_layout_class ) {
$classes[] = 'cm-header-layout-1 adv-style-1';
} elseif ( 'layout-2' === $header_layout_class ) {
$classes[] = 'cm-header-layout-2 adv-style-1';
} elseif ( 'layout-3' === $header_layout_class ) {
$classes[] = 'cm-header-layout-3 adv-style-1';
} elseif ( 'layout-4' === $header_layout_class ) {
$classes[] = 'cm-header-layout-4 adv-style-1';
}
// Proceed only if WooCommerce extra widget option is not enabled as well as
// Proceed only if WooCommerce is enabled and not in WooCommerce pages.
if ( 0 == $woocommerce_widgets_enabled || ( 1 == $woocommerce_widgets_enabled && ( function_exists( 'is_woocommerce' ) && ( ! is_woocommerce() ) ) ) ) :
if ( 'default_layout' === $layout_meta ) {
if ( is_page() ) {
if ( 'right_sidebar' === $colormag_page_sidebar_layout ) {
$classes[] = '';
} elseif ( 'left_sidebar' === $colormag_page_sidebar_layout ) {
$classes[] = 'left-sidebar';
} elseif ( 'no_sidebar_full_width' === $colormag_page_sidebar_layout ) {
$classes[] = 'no-sidebar-full-width';
} elseif ( 'no_sidebar_content_centered' === $colormag_page_sidebar_layout ) {
$classes[] = 'no-sidebar';
}
} elseif ( is_single() ) {
if ( 'right_sidebar' === $colormag_default_post_layout ) {
$classes[] = '';
} elseif ( 'left_sidebar' === $colormag_default_post_layout ) {
$classes[] = 'left-sidebar';
} elseif ( 'no_sidebar_full_width' === $colormag_default_post_layout ) {
$classes[] = 'no-sidebar-full-width';
} elseif ( 'no_sidebar_content_centered' === $colormag_default_post_layout ) {
$classes[] = 'no-sidebar';
}
} elseif ( 'right_sidebar' === $colormag_default_sidebar_layout ) {
$classes[] = '';
} elseif ( 'left_sidebar' === $colormag_default_sidebar_layout ) {
$classes[] = 'left-sidebar';
} elseif ( 'no_sidebar_full_width' === $colormag_default_sidebar_layout ) {
$classes[] = 'no-sidebar-full-width';
} elseif ( 'no_sidebar_content_centered' === $colormag_default_sidebar_layout ) {
$classes[] = 'no-sidebar';
}
} elseif ( 'right_sidebar' === $layout_meta ) {
$classes[] = '';
} elseif ( 'left_sidebar' === $layout_meta ) {
$classes[] = 'left-sidebar';
} elseif ( 'no_sidebar_full_width' === $layout_meta ) {
$classes[] = 'no-sidebar-full-width';
} elseif ( 'no_sidebar_content_centered' === $layout_meta ) {
$classes[] = 'no-sidebar';
}
endif;
// For site layout option.
$site_layout = get_theme_mod( 'colormag_container_layout', 'wide' );
$classes[] = ( 'wide' == $site_layout ) ? 'wide' : 'boxed';
// Add body class for header display type.
$header_display_type = get_theme_mod( 'colormag_header_display_type', 'type_one' );
// For header display type 2.
if ( 'type_two' === $header_display_type ) {
$classes[] = 'header_display_type_one';
}
// For header display type 3.
if ( 'type_three' === $header_display_type ) {
$classes[] = 'header_display_type_two';
}
// Add body class for body skin type.
if ( 'dark' === get_theme_mod( 'colormag_color_skin_setting', 'white' ) ) {
$classes[] = 'dark-skin';
}
// For background image clickable.
$background_image_url_link = get_theme_mod( 'colormag_background_image_link' );
if ( $background_image_url_link ) {
$classes[] = 'clickable-background-image';
}
return $classes;
}
add_filter( 'body_class', 'colormag_body_class' );
/**
* List of allowed social protocols in HTML attributes.
*
* @param array $protocols Array of allowed protocols.
*
* @return array
*/
function colormag_allowed_social_protocols( $protocols ) {
$social_protocols = array(
'skype',
);
return array_merge( $protocols, $social_protocols );
}
add_filter( 'kses_allowed_protocols', 'colormag_allowed_social_protocols' );
/**
* Filters the columns displayed in the Posts list table.
*
* @param string[] $columns An associative array of column headings.
*
* @return mixed
*/
function colormag_posts_column_views( $columns ) {
$columns['post_views'] = esc_html__( 'Total Views', 'colormag' );
return $columns;
}
add_filter( 'manage_posts_columns', 'colormag_posts_column_views' );
/**
* Fires in each custom column in the Posts list table.
*
* @param string $column_name The name of the column to display.
* @param int $post_id The current post ID.
*/
function colormag_posts_custom_column_views( $column_name, $post_id ) {
if ( 'post_views' === $column_name ) {
echo colormag_post_view_display( get_the_ID(), false ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
}
}
add_action( 'manage_posts_custom_column', 'colormag_posts_custom_column_views', 5, 2 );
/**
* Adding the custom generated user field.
*
* @param int $user User id.
*/
function colormag_extra_user_field( $user ) {
?>