Skip to content

Instantly share code, notes, and snippets.

@ville6000
ville6000 / next_permutation.rb
Last active October 1, 2015 15:08
Given a number, find the next higher number that uses the same set of digits. For instance, given the number 38276, the next higher number that uses the digits 2 3 6 7 8 is 38627.
def next_permutation(value)
values = value.to_s(10).split(//).sort
newValue = value + 1
while false == newValue.to_s(10).split(//).sort.eql?(values)
newValue = newValue + 1
end
return newValue
end
@ville6000
ville6000 / functions.php
Last active October 22, 2015 08:19
Exclude pages from WordPress search
<?php
/**
* Exclude footer pages from search
*
* @param $query
*
* @return array
*/
function your_theme_exclude_pages_from_search( $query ) {
if ( $query->is_search ) {
@ville6000
ville6000 / tpl.php
Last active August 29, 2015 14:16
Get page link from title in WordPress
<a href="<?php echo get_permalink( get_page_by_title( 'Contact' ) ); ?>">
<?php _e( 'Contact', 'your_text_domain' ); ?>
</a>
@ville6000
ville6000 / functions.php
Created February 25, 2015 07:56
Dequeue WPML language-selector.css
<?php
define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);
@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
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 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 / 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 / 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 / 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' ) )
);
}