Friday, March 17, 2017

Remove post title from breadcrumb in Genesis

Add below function in your child themes functions.php

//remove post title from breadcrumb
function be_remove_title_from_single_crumb( $crumb, $args ) {
  return substr( $crumb, 0, strrpos( $crumb, $args['sep'] ) );
}
add_filter( 'genesis_single_crumb', 'be_remove_title_from_single_crumb', 10, 2 );

Wednesday, March 8, 2017

Remove Query Strings from Static Resources in Genesis

To Remove Query Strings from Static Resources in Genesis add below code snippet in theme's funtions.php file



function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

This will help your site load faster

How to show list of related posts below post in Genesis

To show related posts sorted using categories add below code snippet in Genesis child theme's fuctions.php file


function related_posts_categories() {
if ( is_single ( ) ) {
global $post;
$count = 0;
$postIDs = array( $post->ID );
$related = '';
$cats = wp_get_post_categories( $post->ID );
$catIDs = array( );{
foreach ( $cats as $cat ) {
$catIDs[] = $cat;
}
$args = array(
'category__in'          => $catIDs,
'post__not_in'          => $postIDs,
'showposts'             => 8,
'ignore_sticky_posts'   => 0,
'orderby'               => 'rand',
'tax_query'             => array(
array(
'taxonomy'  => 'post_format',
'field'     => 'slug',
'terms'     => array(
'post-format-link',
'post-format-status',
'post-format-aside',
'post-format-quote' ),
'operator' => 'NOT IN'
)
)
);
$cat_query = new WP_Query( $args );
if ( $cat_query->have_posts() ) {
while ( $cat_query->have_posts() ) {
$cat_query->the_post();
$related .= '<li><a href="' . get_permalink() . '" rel="bookmark" title="Link to ' . get_the_title() . '">' . get_the_title() . '</a></li>';
}
}
}
if ( $related ) {
printf( '<div><h3>Related stuff:</h3><ul class="myrelated">%s</ul></div>', $related );
}
wp_reset_query();
}
}
add_action( 'genesis_after_entry_content', 'related_posts_categories' );


In above code :

  • Change showposts number to control count of links shown in related posts
  • Class myrelated is defined for the listing. This class can be used to style related posts appearance using CSS

How to change search box text in Genesis

To change search box text add below code snippet in Genesis child theme's functions.php file

add_filter( 'genesis_search_text', 'bg_search_input_text' );
function bg_search_input_text( $text ) {
    
return esc_attr( 'Search this site..' );
}

Add text of your choice instead of highlighted text above.

How to remove self pings in Genesis

Pingbacks or trackbacks are good in a way to showcase your content popularity. But self pingbacks are irritating when you have comment moderation enable in your setup.

Apart from showcasing pingbacks dont stand any value for SEO. If you want to disable them in your Gensis themes then add below code in functions.php file of child theme.

function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );

How to remove emoji support in wordpress to load website faster


Emoji are small animated smiles which replaces text based emoticons like :-)
They look beautiful but they eats few of your bandwidth and hence load time when their support is loaded with webpage.

If you are concerned about your website speed, consider disabling them.

Add below function in your function.php file of child theme of Genesis Framework.

function bt_remove_emoji() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );


add_filter( 'tiny_mce_plugins', 'bt_remove_tinymce_emoji' );
}
add_action( 'init', 'bt_remove_emoji' );

function bt_remove_tinymce_emoji( $plugins ) {

if ( ! is_array( $plugins ) ) {
return array();
}

return array_diff( $plugins, array( 'wpemoji' ) );
}

How to center align pagination in Genesis magazine pro theme


Pagination in Magazine pro theme (Genesis framework) is left aligned by default. To align it to center use below CSS code in additional CSS under Appearance > customize menu.

.archive-pagination {
text-align: center;
}

To add space between pagination number blocks in Magazine pro theme (Genesis framework) use below CSS code :

.archive-pagination li {
margin-left: 5px;
}