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 / functions.php
Created March 19, 2014 18:18
Wordpress - add categories to media files
//Add custom taxonomy for attachments (for using in Library section)
add_action( 'init', 'create_attachmentcat_taxonomy', 0 );
function create_attachmentcat_taxonomy()
{
$labels_att_cats = array(
'name' => _x( 'Категории медиафайлов', 'taxonomy general name' ),
'singular_name' => _x( 'Категория медиафайлов', 'taxonomy singular name' ),
'search_items' => __( 'Искать в категориях медиафайлов' ),
'all_items' => __( 'Все категории медиафайлов' ),
@certainlyakey
certainlyakey / index.php
Created March 20, 2014 10:30
Wordpress - get custom field
<?php
$metaValue = get_post_meta($post->ID, 'sudexmb_regs_address', true);
if ($metaValue) {echo '<div class="contact">'.$metaValue.'</div>';}
?>
@certainlyakey
certainlyakey / functions.php
Created March 22, 2014 16:41
Wordpress - register URL variable
//Add an URL variable (such as `/?opened=true`, check if exists with `get_query_var('opened')`)
function add_query_vars_filter( $vars ){
$vars[] = "allevents";
// $vars[] = "my_var2";
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );
@certainlyakey
certainlyakey / example.css
Last active August 29, 2015 13:59
Embedded CSS for CSS linking demo
/*embedded via https://rawgithub.com/*/
#franklin {border:2px solid red; text-align:center;}
@certainlyakey
certainlyakey / markdown-example.md
Last active August 29, 2015 13:59
Markdown example for web technologies lections

#Русское «дело Дрейфуса»

Автор: Федор Крашенинников, специально для «Кашина»

Об авторе:

  • общественный деятель,
  • политолог,
  • писатель,
  • публицист.
@certainlyakey
certainlyakey / functions.php
Created April 21, 2014 12:07
Wordpress - remove visual editor
// Remove visual editor from a custom post type editing page
function remove_editor_init() {
//remove editor for all registries
remove_post_type_support('registry', 'editor');
//remove editor for pages whose parent page id is 321
if (isset($_GET['post'])) {
$post_id = $_GET['post'];
} else if (isset($_POST['post_ID'])) {
$post_id = $_POST['post_ID'];
@certainlyakey
certainlyakey / functions.php
Created April 25, 2014 21:01
Wordpress - add thumbnail size to media uploader
function pw_show_image_sizes($sizes) {
$sizes['partner-logos'] = __( 'Логотипы партнеров', 'sudex' );
// $sizes['pw-large'] = __( 'Custom Large', 'sudex' );
return $sizes;
}
add_filter('image_size_names_choose', 'pw_show_image_sizes');
@certainlyakey
certainlyakey / header.php
Created April 26, 2014 12:45
Register additional Wordpress options in admin
<?php $myopts = get_option( 'my_option_name', '' ); ?>
<div class="slogan" title="<?php echo $myopts['slogan_translate']; ?>">
@certainlyakey
certainlyakey / functions.php
Created April 26, 2014 09:09
Wordpress - shortcodes menu in editor
//Show all shortcodes in a menu, from here https://tinyurl.com/lbuespy
add_action('media_buttons','add_sc_select',11);
function add_sc_select(){
global $shortcode_tags;
/* ------------------------------------- */
/* enter names of shortcode to exclude below */
/* ------------------------------------- */
$exclude = array("wp_caption", "embed", "caption", "audio", "video", "gallery", "file_modified", "rwmb_meta", "p2p_connected", "p2p_related", "p2p_related");
echo '&nbsp;<select id="sc_select"><option>Shortcode</option>';
foreach ($shortcode_tags as $key => $val){
@certainlyakey
certainlyakey / library.scss
Created April 28, 2014 08:57
Sass mixin - repeat same value for up to 4 properties
//Repeats same value for up to 4 properties
@mixin repeat-value($val, $prop1,$prop2,$prop3:'',$prop4:'') {
#{$prop1}:$val;
#{$prop2}:$val;
@if $prop3 != '' {#{$prop3}:$val;}
@if $prop4 != '' {#{$prop4}:$val;}
}