Skip to content

Instantly share code, notes, and snippets.

View certainlyakey's full-sized avatar

Aleksandr Beliaev certainlyakey

  • Nortal AS
  • Tallinn
View GitHub Profile
@certainlyakey
certainlyakey / Remote Images Grabber
Last active December 12, 2015 12:39
Remote Images Grabber Wordpress plugin v.0.6 with added automated adding of a media file to a custom taxonomy after upload. For Grapes&Corks website
<?php
/*
Plugin Name: Remote Images Grabber updated for G&P
Plugin URI: http://andrey.eto-ya.com/wordpress/my-plugins/remote-images-grabber
Description: Fetches images from an URL or a piece of html-code, saves them directly into your blog media directory, and attaches to the appointed post. Updated with added automated adding of a media file to a custom taxonomy after upload. For Grapes&Corks website
Author: Andrey K.
Author URI: http://andrey.eto-ya.com/
Version: 0.6.1
Requires at least: 2.8.6
Tested up to: 3.4.1
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - register widget areas
function widgets_init_now() {
register_sidebar( array(
'name' => 'В шапке',
'id' => 'header'
) );
register_sidebar( array(
'name' => 'Левая колонка',
'id' => 'aside_left'
) );
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - hide admin bar
add_filter('show_admin_bar', '__return_false');
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - custom content function with manual word limit
//Custom content function with words manual limit
function content($limit, $postid, $showmorelink = true) { //Normally, the second parameter provided is '$post->ID'
$content = explode(' ', get_post_field('post_content', $postid), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content);
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = strip_tags($content,'<br />');
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - add excerpts to pages
//add excerpts to pages
add_action( 'init', 'add_excerpts_to_pages' );
function add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - the_category expanded to support custom taxonomies, with possibility to exclude certain categories or terms
//the_category expanded to support custom taxonomies, with possibility to exclude certain categories/terms
function catOut($category,$tax,$showlink) {
$text = '';
$text .= '<li>';
if ($showlink) {$text .= '<a href="' . get_term_link($category->term_id,$tax).'" title="'.$category->name.'"'.'>';}
$text .= $category->name;
if ($showlink) {$text .= '</a>';}
$text .= '</li>';
return $text;
}
@certainlyakey
certainlyakey / page.php
Last active August 29, 2015 13:56
Wordpress - custom gallery from WP post gallery
<?php
$args = array(
'numberposts' => -1, // Using -1 loads all posts
'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
'order'=> 'ASC',
'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
'post_status' => null,
'post_type' => 'attachment'
);
@certainlyakey
certainlyakey / functions.php
Last active October 28, 2017 23:25
Wordpress - WP post gallery code cleaner
<?
function cleaner_gallery($output, $attr) {
$base_class = 'c-content-gallery';
if ( is_feed() ) {
return $output;
}
if ( isset( $attr['orderby'] ) ) {
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
if ( !$attr['orderby'] ) {
unset( $attr['orderby'] );
@certainlyakey
certainlyakey / functions.php
Created March 3, 2014 21:34
Wordpress - register custom post type
//Add custom post type (books)
function book_custompost_init() {
$labels_books = array(
'name' => _x('Публикации', 'post type general name'),
'singular_name' => _x('Публикация', 'post type singular name'),
'add_new' => _x('Добавить', 'book'),
'add_new_item' => __('Добавить '),
'edit_item' => __('Редактировать публикацию'),
'new_item' => __('Новая публикация'),
'all_items' => __('Все публикации'),
@certainlyakey
certainlyakey / functions.php
Created March 3, 2014 21:34
Wordpress - register custom taxonomy for custom post type
//Create categories for books
function create_booktag_taxonomy() {
$labels_booktag = array(
'name' => _x( 'Тэги публикаций', 'taxonomy general name' ),
'singular_name' => _x( 'Тэг публикаций', 'taxonomy singular name' ),
'search_items' => __( 'Искать тэги публикаций' ),
'all_items' => __( 'Все тэги публикаций' ),
'edit_item' => __( 'Редактировать' ),
'update_item' => __( 'Обновить' ),
'add_new_item' => __( 'Добавить тэг публикаций' ),