Skip to content

Instantly share code, notes, and snippets.

View SErr0r's full-sized avatar

Gennady Yudenko SErr0r

View GitHub Profile
@SErr0r
SErr0r / index.php
Created June 20, 2016 15:04
Wordpress WPML Custom Language switcher
<?php
//* Just add this anywhere in yopur template where you want language switcher to appear.
//* This switcher just shows the flags. But you can make it work anyway you like
?>
<ul class="lang-switcher">
<?php
$languages = icl_get_languages('skip_missing=N&orderby=KEY&order=DIR&link_empty_to=str');
foreach($languages as $language){
$flag = $language['country_flag_url'];
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:46
Logout to Primary WordPress Menu
<?php
add_filter( 'wp_nav_menu_items', 'add_login_logout_to_primary_menu', 10, 2 );
function add_login_logout_to_primary_menu( $items, $args ) {
if( 'primary' === $args->theme_location ) :
if (is_user_logged_in()) {
$items .= '<li><a href="'.wp_logout_url(home_url()).'">Logout</a></li>';
} else {
$items .= '<li><a href="'.wp_login_url().'">Login</a></li>';
}
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:44
bootstrap_pager
<?php
function bootstrap_pager($pages = '', $range = 2) {
$showitems = ( $range * 2 )+1;
global $paged;
if ( empty( $paged ) ) $paged = 1;
if ( $pages == '' ) {
global $wp_query;
$pages = $wp_query->max_num_pages;
if ( !$pages ) {
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:39
WPML - Add language class to body element
<?php
# WPML - Add language class to body element
function append_language_class($classes) {
$classes[] = 'lang-' . ICL_LANGUAGE_CODE;
return $classes;
}
add_filter('body_class', 'append_language_class');
?>
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:37
Enable WordPress debugging
<?php
/*
* Debugging (Development)
*/
// Enable WordPress debugging (NEVER LEAVE ENABLED ON PRODUCTION SITES!)
define('WP_DEBUG', false);
// Enable Debug logging to the /wp-content/debug.log file
// define('WP_DEBUG_LOG', true);
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:32
Customize TinyMCE in WordPress
<?php
// Customize Font Family, Size, and Color Options
function vital_tinymce($options) {
$options['fontsize_formats'] = '0.75em 0.875em 1em 1.125em 1.25em 1.375em 1.5em 1.75em 1.875em 2em';
// Color Picker
$options['textcolor_map'] = '['.'
"ffffff", "White",
"000000", "Black"
'.']';
// Font Families
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:31
Font Awesome Shortcode
<?php
//* Font Awesome
//* EXAMPLE: [fa icon="fa-search" color="#555555"]
function font_awesome_shortcode( $atts ) {
extract( shortcode_atts( array(
'icon' => 'fa-question-circle',
'color' => '#555555'
), $atts ) );
return "<span class='fa {$icon}' style='color:{$color}'></span>";
}
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:27
Divide content at the <! --more--> tag
<?php
$description = get_field('descripton');
if( strpos($description, '<!--more-->') >= 1 ) {
$more_position = 11 + strpos($description, '<!--more-->');
$before_more = substr($description, 0, $more_position);
$after_more = substr($description, $more_position); ?>
<div class="excerpt">
<?php echo $before_more; ?>
</div>
<div class="read-more">
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:26
Filter by Taxonomy with AND/OR Relation between multiple taxonomies
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'movie_genre',
'field' => 'slug',
'terms' => array( 'action', 'comedy' )
),
@SErr0r
SErr0r / function.php
Created June 20, 2016 14:19
Add favicon and touch icon to header
<?php
function add_favicons() {
echo '<link rel="shortcut icon" href="' . get_stylesheet_directory_uri() . '/images/favicon.ico">'."\n";
echo '<link rel="apple-touch-icon-precomposed" href="' . get_stylesheet_directory_uri() . '/images/apple-touch-icon-precomposed.png" />'."\n";
}
add_action('wp_head', 'add_favicons');
?>