Skip to content

Instantly share code, notes, and snippets.

@ville6000
ville6000 / script.js
Created March 23, 2015 11:39
Scroll to element
$(function () {
$("#btn").on('click', function() {
$('html, body').animate({
scrollTop: $("#scrollToElementId").offset().top
}, 400);
});
});
@ville6000
ville6000 / functions.php
Last active October 22, 2015 08:24
Tag support for WordPress pages
<?php
function my_theme_init() {
register_taxonomy_for_object_type( 'post_tag', 'page' );
}
add_action( 'init', 'my_theme_init' );
function my_theme_tags_support_query( $wp_query ) {
if ( $wp_query->get( 'tag' ) ) {
$wp_query->set( 'post_type', 'any' );
@ville6000
ville6000 / functions.php
Last active October 22, 2015 08:24
Remove WordPress gallery shortcodes default styles
<?php
function my_theme_default_gallery_style() {
return false;
}
add_filter( 'use_default_gallery_style', 'my_theme_default_gallery_style' );
@ville6000
ville6000 / functions.php
Last active August 29, 2015 14:16
Add dynamic version number to WordPress style.css
<?php
function your_theme_styles() {
wp_enqueue_style(
'style',
get_stylesheet_directory_uri() . '/style.css',
false,
date( 'dmYhi', filemtime( get_stylesheet_directory() . '/style.css' ) )
);
}
@ville6000
ville6000 / style.css
Last active August 29, 2015 14:16
Styles for responsive iframe
.iframe-responsive-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
}
.iframe-responsive-container iframe {
position: absolute;
left: 0;
@ville6000
ville6000 / main.js
Last active October 22, 2015 08:25
Wrap iframes with responsive container
(function ($) {
$(function () {
$('iframe').wrap("<div class='iframe-responsive-container'></div>");
});
})(jQuery);
@ville6000
ville6000 / functions.php
Created February 27, 2015 12:21
Add category support to pages
function my_theme_init() {
register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'my_theme_init' );
@ville6000
ville6000 / functions.php
Last active November 10, 2015 08:04
Remove extra 10 pixel space from WordPress caption
<?php
function my_theme_fix_extra_caption_padding( $atts ) {
if ( ! empty( $atts['width'] ) ) {
$atts['width'] -= 10;
}
return $atts;
}
add_filter( 'shortcode_atts_caption', 'my_theme_fix_extra_caption_padding' );
@ville6000
ville6000 / functions.php
Created February 25, 2015 08:07
Exclude page from Wordpress search
function your_theme_exclude_pages_from_search( $query ) {
$query->set( 'post__not_in', PAGE_ID_HERE );
return $query;
}
add_filter( 'pre_get_posts', 'your_theme_exclude_pages_from_search' );
@ville6000
ville6000 / functions.php
Created February 25, 2015 07:56
Dequeue WPML language-selector.css
<?php
define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);