tag based on what is being viewed.
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string The filtered title.
*/
/*function alchem_wp_title( $title, $sep ) {
if ( is_feed() ) {
return $title;
}
global $page, $paged;
// Add the blog name
$title .= get_bloginfo( 'name', 'display' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
// Add a page number if necessary:
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( __( 'Page %s', 'alchem' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'alchem_wp_title', 10, 2 );*/
if ( ! function_exists( '_wp_render_title_tag' ) ) {
function alchem_slug_render_title() {
?>
is_author() && isset( $wp_query->post ) ) {
$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
}
}
add_action( 'wp', 'alchem_setup_author' );
global $wp_embed;
add_filter( 'the_excerpt', array( $wp_embed, 'autoembed' ), 9 );
function alchem_add_pages_link( $content ){
$pages = wp_link_pages(
array(
'before' => '' . __( 'Page: ', 'alchem' ),
'after' => '
',
'echo' => false )
);
if ( $pages == '' ){
return $content;
}
return $content . $pages;
}
add_filter( 'the_content', 'alchem_add_pages_link' );
add_filter( 'the_password_form', 'alchem_password_form' );
function alchem_password_form(){
global $post;
$form = '
';
return $form;
}
add_action( 'widgets_init', 'alchem_widgets' );
function alchem_widgets(){
global $sidebars ;
$sidebars = array(
'' => __( 'No Sidebar', 'alchem' ),
'default_sidebar' => __( 'Default Sidebar', 'alchem' ),
'sidebar-1' => __( 'Sidebar 1', 'alchem' ),
'sidebar-2' => __( 'Sidebar 2', 'alchem' ),
'sidebar-3' => __( 'Sidebar 3', 'alchem' ),
'sidebar-4' => __( 'Sidebar 4', 'alchem' ),
'sidebar-5' => __( 'Sidebar 5', 'alchem' ),
'sidebar-5' => __( 'Sidebar 5', 'alchem' ),
'sidebar-6' => __( 'Sidebar 6', 'alchem' ),
'footer_widget_1' => __( 'Footer Widget 1', 'alchem' ),
'footer_widget_2' => __( 'Footer Widget 2', 'alchem' ),
'footer_widget_3' => __( 'Footer Widget 3', 'alchem' ),
'footer_widget_4' => __( 'Footer Widget 4', 'alchem' ),
'left_sidebar_404' => __( '404 Page Left Sidebar', 'alchem' ),
'right_sidebar_404' => __( '404 Page Right Sidebar', 'alchem' ),
);
foreach( $sidebars as $k => $v ){
if( $k !='' ){
register_sidebar(array(
'name' => $v,
'id' => $k,
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
));
}
}
}
/**
* Convert Hex Code to RGB
* @param string $hex Color Hex Code
* @return array RGB values
*/
function alchem_hex2rgb( $hex ) {
if ( strpos( $hex,'rgb' ) !== FALSE ) {
$rgb_part = strstr( $hex, '(' );
$rgb_part = trim($rgb_part, '(' );
$rgb_part = rtrim($rgb_part, ')' );
$rgb_part = explode( ',', $rgb_part );
$rgb = array($rgb_part[0], $rgb_part[1], $rgb_part[2], $rgb_part[3]);
} elseif( $hex == 'transparent' ) {
$rgb = array( '255', '255', '255', '0' );
} else {
$hex = str_replace( '#', '', $hex );
if( strlen( $hex ) == 3 ) {
$r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
$g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
$b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
} else {
$r = hexdec( substr( $hex, 0, 2 ) );
$g = hexdec( substr( $hex, 2, 2 ) );
$b = hexdec( substr( $hex, 4, 2 ) );
}
$rgb = array( $r, $g, $b );
}
return $rgb; // returns an array with the rgb values
}
add_filter('upload_mimes', 'alchem_filter_mime_types');
function alchem_filter_mime_types($mimes)
{
$mimes['ttf'] = 'font/ttf';
$mimes['woff'] = 'font/woff';
$mimes['svg'] = 'font/svg';
$mimes['eot'] = 'font/eot';
return $mimes;
}
/* =============================================================================
Include the Google Fonts
========================================================================== */
global $of_options,$default_theme_fonts;
// default fonts used in this theme, even though there are no google fonts
$default_theme_fonts = array(
'Arial, Helvetica, sans-serif' => 'Arial, Helvetica, sans-serif',
"'Arial Black', Gadget, sans-serif" => "'Arial Black', Gadget, sans-serif",
"'Bookman Old Style', serif" => "'Bookman Old Style', serif",
"'Comic Sans MS', cursive" => "'Comic Sans MS', cursive",
"Courier, monospace" => "Courier, monospace",
"Garamond, serif" => "Garamond, serif",
"Georgia, serif" => "Georgia, serif",
"Impact, Charcoal, sans-serif" => "Impact, Charcoal, sans-serif",
"'Lucida Console', Monaco, monospace" => "'Lucida Console', Monaco, monospace",
"'Lucida Sans Unicode', 'Lucida Grande', sans-serif" => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
"'MS Sans Serif', Geneva, sans-serif" => "'MS Sans Serif', Geneva, sans-serif",
"'MS Serif', 'New York', sans-serif" => "'MS Serif', 'New York', sans-serif",
"'Palatino Linotype', 'Book Antiqua', Palatino, serif" => "'Palatino Linotype', 'Book Antiqua', Palatino, serif",
"Tahoma, Geneva, sans-serif" => "Tahoma, Geneva, sans-serif",
"'Times New Roman', Times, serif" => "'Times New Roman', Times, serif",
"'Trebuchet MS', Helvetica, sans-serif" => "'Trebuchet MS', Helvetica, sans-serif",
"Verdana, Geneva, sans-serif" => "Verdana, Geneva, sans-serif"
);
defined('OF_FONT_DEFAULTS') or define('OF_FONT_DEFAULTS', serialize($default_theme_fonts));
include_once( get_template_directory().'/inc/google-fonts.php' );
global $google_fonts_array;
function of_filter_recognized_font_families( $array, $field_id ) {
global $google_fonts_array;
// loop through the cached google font array if available and append to default fonts
$font_array = array();
if($google_fonts_array){
foreach($google_font_array as $index => $value){
$font_array[$value['family']] = $value['family'];
}
}
// put both arrays together
$array = array_merge(unserialize(OF_FONT_DEFAULTS), $font_array);
return $array;
}
// get typography
function alchem_get_typography($value){
global $google_fonts_array,$default_theme_fonts;
$return = "";
if ( is_array($value) && alchem_array_keys_exists( $value, array( 'font-color', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'letter-spacing', 'line-height', 'text-decoration', 'text-transform' ) ) ) {
$font = array();
if ( ! empty( $value['font-color'] ) )
$font[] = "color: " . $value['font-color'] . " !important;";
if ( ! empty( $value['font-family'] ) ) {
if( isset($google_fonts_array[$value['font-family']]) )
$font[] = "font-family: " . $google_fonts_array[$value['font-family']]['family'] . ";";
else
$font[] = "font-family: " . $default_theme_fonts[$value['font-family']] . ";";
}
if ( ! empty( $value['font-size'] ) )
$font[] = "font-size: " . $value['font-size'] . ";";
if ( ! empty( $value['font-style'] ) )
$font[] = "font-style: " . $value['font-style'] . ";";
if ( ! empty( $value['font-variant'] ) )
$font[] = "font-variant: " . $value['font-variant'] . ";";
if ( ! empty( $value['font-weight'] ) )
$font[] = "font-weight: " . $value['font-weight'] . ";";
if ( ! empty( $value['letter-spacing'] ) )
$font[] = "letter-spacing: " . $value['letter-spacing'] . ";";
if ( ! empty( $value['line-height'] ) )
$font[] = "line-height: " . $value['line-height'] . ";";
if ( ! empty( $value['text-decoration'] ) )
$font[] = "text-decoration: " . $value['text-decoration'] . ";";
if ( ! empty( $value['text-transform'] ) )
$font[] = "text-transform: " . $value['text-transform'] . ";";
/* set $value with font properties or empty string */
$return = ! empty( $font ) ? implode( " ", $font ) : '';
}
return $return;
}
/**
* Modifies WordPress's built-in comments_popup_link() function to return a string instead of echo comment results
*/
function alchem_get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
global $wpcommentspopupfile, $wpcommentsjavascript;
$id = get_the_ID();
if ( false === $zero ) $zero = __( 'No Comments', 'alchem');
if ( false === $one ) $one = __( '1 Comment', 'alchem');
if ( false === $more ) $more = __( '% Comments', 'alchem');
if ( false === $none ) $none = __( 'Comments Off', 'alchem');
$number = get_comments_number( $id );
$str = '';
if ( 0 == $number && !comments_open() && !pings_open() ) {
$str = '' . $none . '';
return $str;
}
if ( post_password_required() ) {
return '';
}
$str = ' 0 ) );
$str .= apply_filters( 'comments_popup_link_attributes', '' );
$str .= ' title="' . esc_attr( sprintf( __('Comment on %s', 'alchem'), $title ) ) . '">';
$str .= alchem_get_comments_number_str( $zero, $one, $more );
$str .= '';
return $str;
}
/**
* Modifies WordPress's built-in comments_number() function to return string instead of echo
*/
function alchem_get_comments_number_str( $zero = false, $one = false, $more = false, $deprecated = '' ) {
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, '1.3' );
$number = get_comments_number();
if ( $number > 1 )
$output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments', 'alchem') : $more);
elseif ( $number == 0 )
$output = ( false === $zero ) ? __('No Comments', 'alchem') : $zero;
else // must be one
$output = ( false === $one ) ? __('1 Comment', 'alchem') : $one;
return apply_filters('comments_number', $output, $number);
}
// get summary
function alchem_get_summary(){
$excerpt_or_content = alchem_option('excerpt_or_content','excerpt');
$excerpt_length = alchem_option('excerpt_length','55');
if( $excerpt_or_content == 'full_content' ){
$output = get_the_content();
}
else{
$output = get_the_excerpt();
if( is_numeric($excerpt_length) && $excerpt_length !=0 )
$output = alchem_content_length($output, $excerpt_length );
}
return $output;
}
function alchem_content_length($content, $limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
// get post content css class
function alchem_get_content_class( $sidebar = '' ){
if( $sidebar == 'left' )
return 'left-aside';
if( $sidebar == 'right' )
return 'right-aside';
if( $sidebar == 'both' )
return 'both-aside';
if( $sidebar == 'none' )
return 'no-aside';
return 'no-aside';
}
// get breadcrumbs
function alchem_get_breadcrumb( $options = array()){
global $post,$wp_query ;
$postid = isset($post->ID)?$post->ID:"";
$show_breadcrumb = "";
if ( 'page' == get_option( 'show_on_front' ) && ( '' != get_option( 'page_for_posts' ) ) && $wp_query->get_queried_object_id() == get_option( 'page_for_posts' ) ) {
$postid = $wp_query->get_queried_object_id();
}
if(isset($postid) && is_numeric($postid)){
$show_breadcrumb = get_post_meta( $postid, '_alchem_show_breadcrumb', true );
}
if($show_breadcrumb == 'yes' || $show_breadcrumb==""){
alchem_breadcrumb_trail( $options);
}
}
// footer tracking code
function alchem_tracking_code(){
$tracking_code = alchem_option('tracking_code');
echo $tracking_code;
}
add_action('wp_footer', 'alchem_tracking_code');
// Space before
function alchem_space_before_head(){
$space_before_head = alchem_option('space_before_head');
echo $space_before_head;
}
add_action('wp_head', 'alchem_space_before_head');
// Space before