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
Last active October 28, 2017 19:42
Save ACF custom field as post title (Wordpress)
function update_post_title_from_customfield( $post_id ) {
$saved_post = array();
$saved_post['ID'] = $post_id;
$field = get_field('date_date_day');
if (get_post_type() == 'date' && $field) {
$saved_post['post_title'] = $field;
}
@certainlyakey
certainlyakey / child.twig
Last active August 17, 2017 14:57
A way to move Twig block to different places in template (keeping the backend variables intact)
{% extends 'parent.twig' %}
{# remove meta from its default location #}
{% block aside_meta '' %}
{% block article %}
{{ block('meta') }}
{% endblock %}
@certainlyakey
certainlyakey / _mixins.scss
Created June 2, 2017 10:36
Text styling base variable and mixin reusing it
$font-sizes: (
xxxs: (fs:12px, lh:1.167),
xxs: (fs:14px, lh:1.21),
xs: (fs:17px, lh:1.235),
s: (fs:19px, lh:1.21),
m: (fs:21px, lh:1.19),
l: (fs:35px, lh:1.14),
xl: (fs:48px, lh:1.167),
xxl: (fs:100px, lh:1.18),
xxxl: (fs:110px, lh:0.735)
@certainlyakey
certainlyakey / functions.php
Last active January 17, 2017 23:02
Load more posts via ajax — basics
<?php
function mytheme_loadmore_posts_ajax_callback() {
$args = array( 'post_type' => 'post', 'offset' => $_POST['offset'] );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
@certainlyakey
certainlyakey / functions.php
Created December 29, 2016 08:47
Remove all classes in a Wordpress-based menus, except those given
// Remove all classes in a Wordpress-based menus, except those given
function css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array('current-menu-item','current_page_item','current-page-ancestor','current-menu-ancestor','current-menu-parent')) : '';
}
add_filter('nav_menu_css_class', 'css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'css_attributes_filter', 100, 1);
@certainlyakey
certainlyakey / scripts.js
Created September 6, 2016 08:06
Do not show outline when clicking a toggleable element while displaying it when tabbing through it
$('a.header').mouseup(function() {
this.blur();
});
@certainlyakey
certainlyakey / functions.php
Created June 26, 2016 22:13
Completely remove vanilla Wordpress tags and categories
//Remove categories and tags
function unregister_categories() {
register_taxonomy( 'category', array(), array('show_in_nav_menus' => false) );
}
add_action( 'init', 'unregister_categories' );
unregister_widget( 'WP_Widget_Categories' );
function unregister_tags(){
register_taxonomy('post_tag', array(), array('show_in_nav_menus' => false));
}
@certainlyakey
certainlyakey / functions.php
Created June 3, 2016 16:11
Add metabox (yes/no select) to media attachment edit page
// add metabox to attachment edit page that will allow users to choose if to show this image in logo gallery
function add_our_attachment_meta(){
add_meta_box( 'custom-attachment-meta-box',
'Дополнительные настройки медиафайла',
'attachment_metabox_callback',
'attachment',
'normal',
'low'
);
}
@certainlyakey
certainlyakey / views-view-unformatted--pagename.tpl.php
Created April 13, 2016 06:51
Programatically add a block to a Drupal view
<?php
$nid = $variables['view']->result[$id]->nid;
$array = array($nid);
$view = views_get_view('travel_destination_header');
$view->set_display("block");
$view->set_arguments($array);
$view->pre_execute();
$view->execute();
$content = $view->render();
@certainlyakey
certainlyakey / node--country.tpl.php
Created April 5, 2016 11:16
Show summary in a node template
print render(field_view_field('node', $node, 'field_my_textfield', array(
'label'=>'hidden',
'type' => 'text_summary_or_trimmed',
'settings'=>array('trim_length' => 10),
)));