Skip to content

Instantly share code, notes, and snippets.

View tevashov's full-sized avatar

Teff tevashov

View GitHub Profile
@tevashov
tevashov / Asset.js
Last active October 27, 2022 21:42
Event if and which key was pressed #jQuery
$(function() {
$(document).keypress(function(e){
switch(e.which){
// "ENTER"
case 13:
alert('enter pressed');
break;
// "s"
case 115:
@tevashov
tevashov / functions.php
Last active October 27, 2022 21:19
Change WordPress Login Logo #WP
// Custom WordPress Login Logo
function login_css() {
    wp_enqueue_style( 'login_css', get_template_directory_uri() . '/css/login.css' );
}
add_action('login_head', 'login_css');
@tevashov
tevashov / Asset.js
Last active October 27, 2022 21:35
Event if an image is loaded or not with #jQuery
var imgsrc = 'img/image1.png';
$('<img/>').load(function () {
alert('image loaded');
}).error(function () {
alert('error loading image');
}).attr('src', imgsrc);
@tevashov
tevashov / Asset.php
Last active October 27, 2022 21:54
Replace “Howdy, admin” in WordPress admin bar #WP
function replace_howdy( $wp_admin_bar ) {
    $my_account=$wp_admin_bar->get_node('my-account');
    $newtitle = str_replace( 'Howdy,', 'Logged in as', $my_account->title );           
    $wp_admin_bar->add_node( array(
        'id' => 'my-account',
        'title' => $newtitle,
    ) );
}
add_filter( 'admin_bar_menu', 'replace_howdy',25 );
@tevashov
tevashov / Asset.css
Created March 15, 2013 19:34
Basic typography
.content {
font: 1em/1.4 Segoe, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
.title {
font: 1.7em/1.2 Baskerville, "Baskerville old face", "Hoefler Text", Garamond, "Times New Roman", serif;
}
.code {
font: 0.8em/1.6 Monaco, Mono-Space, monospace;
@tevashov
tevashov / Asset.js
Last active October 27, 2022 21:43
Write your own selectors #jQuery
//extend the jQuery functionality
$.extend($.expr[':'], {
//name of your special selector
moreThanAThousand : function (a){
//Matching element
return parseInt($(a).html()) > 1000;
}
});
@tevashov
tevashov / Asset.js
Last active October 27, 2022 21:53
Test if an element is visible #jQuery
if($(element).is(":visible")) {
// The element is Visible
}
@tevashov
tevashov / Asset.php
Last active October 27, 2022 21:54
Remove Dashboard Widgets According to User Role #WP
function customize_meta_boxes() {  
    global $current_user;  
    get_currentuserinfo();  
    if ($current_user->user_level < 3)  
        remove_meta_box('postcustom','post','normal');  
    }  
add_action('admin_init','customize_meta_boxes');  
@tevashov
tevashov / Asset.js
Last active October 27, 2022 21:43
Fade out an image into another one (replacing) #jQuery
$('imageelement').fadeOut(function() {
$(this).load(function() {
$(this).fadeIn();
}).attr('src', AnotherSource);
});
@tevashov
tevashov / Asset.php
Last active October 27, 2022 21:56
Get posts from custom tax grouped by terms (WP API) #WP
$myterms = get_terms('retouch_types', 'orderby=none&hide_empty');
foreach ($myterms as $term) {
setup_postdata($post);
$term->name;
//select posts in this category, and of a specified content type
$posts = get_posts( array(
'post_type' => 'retouch',
'tax_query' => array(