Skip to content

Instantly share code, notes, and snippets.

@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 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 / 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 / template.php
Created March 26, 2015 12:38
WP_Query with a date filter on a custom field
<?php
$the_query = new WP_Query( array(
'post_type' => 'trip',
'post_per_page' => $limit,
'meta_key' => 'wpcf-start-date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
'key' => 'wpcf-start-date',
'value' => current_time( 'timestamp' ),
@ville6000
ville6000 / template.php
Last active October 22, 2015 08:18
Get translated permalink with WPML
<?php $icl_object_id = icl_object_id( get_the_ID(), 'post', true ); ?>
<a href="<?php echo get_permalink( $icl_object_id ); ?>">
<?php _e( 'Read more', 'your_domain' ); ?>
</a>
@ville6000
ville6000 / index.php
Last active October 22, 2015 08:26
Get post thumbnail URL
<?php
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'image-size' );
$url = $thumb['0'];
@ville6000
ville6000 / functions.php
Last active October 22, 2015 08:26
Get current url in WordPress
<?php
function get_current_url() {
global $wp;
return add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $wp->request ) );
}
@ville6000
ville6000 / functions.php
Last active April 14, 2017 05:18
Change post per page
<?php
function change_posts_per_page( $query ) {
if ( is_main_query() && is_archive() ) {
$query->set( 'posts_per_page', -1 );
}
}
add_action( 'pre_get_posts', 'change_posts_per_page' );
@ville6000
ville6000 / script.js
Created May 13, 2015 06:22
Disable scroll wheel zoom on Google Maps
var map;
var mapOptions = {
zoom: 15,
scrollwheel: false,
center: new google.maps.LatLng( latitude, longitude )
};
map = new google.maps.Map(
document.getElementById( 'map-canvas' ),
mapOptions
@ville6000
ville6000 / index.php
Last active October 22, 2015 08:27
Variable demo
<?php
$post_idx = 0;
if ( have_posts()) {
while ( have_posts()) {
the_post();
// $post_idx is not available in content-page.php
get_template_part('content', 'page');
$post_idx += 1;
}