Skip to content

Instantly share code, notes, and snippets.

@aldolat
Last active December 4, 2016 07:32
Show Gist options
  • Save aldolat/632de15f5aaf11917610e3db5d779868 to your computer and use it in GitHub Desktop.
Save aldolat/632de15f5aaf11917610e3db5d779868 to your computer and use it in GitHub Desktop.
Remove title attribute and shorten title
<?php
// Add this function to your functions.php file or to your functions plugin.
function posts_in_sidebar_hacks() {
wp_enqueue_script( 'pis-add-hacks', get_template_directory_uri() . '/js/pis-hacks.js', array( 'jquery' ), false, true );
}
add_action( 'wp_enqueue_scripts', 'posts_in_sidebar_hacks' );
jQuery(document).ready(function(){
// Remove the title attribute from all links with "pis-thumbnail-link" class.
jQuery('a.pis-thumbnail-link').removeAttr("title");
// Shorten all links with "pis-title-link" class to 9 characters if they are longer than 10 characters.
jQuery('a.pis-title-link').each(function(){
var str = jQuery(this).text();
str = str.trim(str);
if (str.length > 10) {
jQuery(this).text(str.substr(0, 9));
jQuery(this).append('&hellip;');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment