Skip to content

Instantly share code, notes, and snippets.

View tiberiur's full-sized avatar

Tiberiu Rus tiberiur

View GitHub Profile
@tiberiur
tiberiur / countingOccurrences()
Last active April 13, 2016 11:58
[JS] Counting Occurrences of Substrings
function countingOccurrences(string, subString)
{
var foundAtPosition = 0;
var count = 0;
while (foundAtPosition != -1) {
foundAtPosition = string.indexOf(subString, foundAtPosition);
if (foundAtPosition != -1) {
count++;
foundAtPosition++;
@tiberiur
tiberiur / fileName()
Last active April 13, 2016 11:58
[JS] File path or the name of currently loaded webpage
function fileName()
{
var fileName = window.location.href;
fileName = fileName.substr(fileName.lastIndexOf("/") - 1);
return fileName;
}
@tiberiur
tiberiur / getBrowserName()
Last active April 13, 2016 11:57
[JS] Get the browser name using navigator object
function getBrowserName()
{
lsBrowser = navigator.userAgent;
if ( lsBrowser.indexOf("MSIE") >= 0 ) {
lsBrowser = "MSIE";
} else if ( lsBrowser.indexOf("Firefox") >= 0 ) {
lsBrowser = "Firefox";
} else if ( lsBrowser.indexOf("Chrome") >= 0 ) {
lsBrowser = "Chrome";
@tiberiur
tiberiur / getBrowserVersion()
Last active April 13, 2016 11:57
[JS] Get browser version using navigator object.
function getBrowserVersion()
{
var findIndex;
var browserVersion = 0;
var browser = getBrowserName();
browserVersion = navigator.userAgent;
findIndex = browserVersion.indexOf(browser) + browser.length + 1;
browserVersion = parseFloat(browserVersion.substring(findIndex, findIndex + 3));
@tiberiur
tiberiur / functions.php
Last active April 13, 2016 11:58
[WP] Enable shortcodes in Text Widget
add_filter('widget_text', 'do_shortcode');
@tiberiur
tiberiur / functions.php
Created April 13, 2016 11:59
[WP] Modify 'read more' link
function modify_read_more_link() {
return '<a class="post__link" href="' . get_permalink() . '">Read more &rsaquo;</a>';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
@tiberiur
tiberiur / functions.php
Created April 13, 2016 11:59
[WP] Add page title in body class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) && !is_home() ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );
@tiberiur
tiberiur / functions.php
Created April 13, 2016 12:00
[WP] Remove default editor
function remove_wysiwyg()
{
remove_post_type_support('page', 'editor');
}
add_action('init', 'remove_wysiwyg', 10);
@tiberiur
tiberiur / functions.php
Created April 13, 2016 12:01
[WP] Remove emoji
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
@tiberiur
tiberiur / local.xml
Created April 14, 2016 09:02
[MAGENTO] Add custom breadcrumbs from XML
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo>
<label>Home</label>
<title>Home</title>
<link>/home</link>
</crumbInfo>
</action>
<action method="addCrumb">