Skip to content

Instantly share code, notes, and snippets.

@twentyfortysix
twentyfortysix / theme-switch.php
Created October 11, 2015 14:09
Theme test drive like plugin (wordpress)
<?php
/*
Plugin Name: Theme drive
Description: Display different theme to user if logged in as admin
Author: Kyle Barber
*/
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');
function change_theme($theme) {
@twentyfortysix
twentyfortysix / WP - get secondary thumbnail
Last active February 13, 2016 19:42
get_multithumbnail
$heading_image_url = MultiPostThumbnails::get_post_thumbnail_url('page', 'project-headr',$post->ID, 'full');
@twentyfortysix
twentyfortysix / jsroll_to.js
Last active February 13, 2016 19:40
JQuery - anim. scroll to anchor
function() {
$('a.scroll').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
@twentyfortysix
twentyfortysix / next_prev_pages.php
Last active September 17, 2016 10:28
WP - get next-prev Pages in menu_order
<?php
// get the id of page laying next to the given one
// and only those that are chosen by meta value show_in_selected = 1
function prev_next_page($step){
global $post;
$actual_menu_order = $post->menu_order;
$args = array(
'post_type' => $post->post_type,
'posts_per_page' => -1, // we have to get all in order to get cycle results
'post_status' => 'publish',
@twentyfortysix
twentyfortysix / wpml_custom_switch.php
Last active February 13, 2016 19:39
WP - WPML - custom language_switch
if (function_exists('icl_get_languages')){
$languages = icl_get_languages('skip_missing=0');
$lang_html = '';
foreach($languages as $lang){
$lang_html .= '<div';
if ( $lang['native_name'] == ICL_LANGUAGE_NAME){
$lang_html .= ' class="current-menu-item current_language lng"';
}
else{
$lang_html .= ' class="lng"';
@twentyfortysix
twentyfortysix / custom_menu.php
Last active February 13, 2016 19:37
WP - bootstrap menu generated from pages, excluding custim_meta defined
function custom_menu(){
$o = '';
$pid = get_queried_object_id();
$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => 0,
'order' => 'ASC',
@twentyfortysix
twentyfortysix / wp-cli.shell
Created February 13, 2016 19:36
wp-cli - initial live saver
wp plugin install custom-content-type-manager simple-image-sizes codepress-admin-columns adminimize
@twentyfortysix
twentyfortysix / register_media_field.php
Last active February 15, 2016 13:07
WP - register custom field for media
<?php
function be_attachment_field_credit( $form_fields, $post ) {
//
// ---- CS ---
//
$form_fields['media_date'] = array(
'label' => 'Datum',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'media_date', true ),
// 'helps' => 'datace',
@twentyfortysix
twentyfortysix / fire_up_wp.sh
Last active April 17, 2016 15:06
initial wp installation
!/bin/bash -e
#modified to personal user by 2046, original - https://www.ltconsulting.co.uk/automated-wordpress-installation-with-bash-wp-cli/
wpuser='2046'
clear
echo "================================================================="
echo "Awesome WordPress Installer!!"
echo "================================================================="
@twentyfortysix
twentyfortysix / multiple_meta_query_sorting.php
Last active May 19, 2023 14:23
WP - sort by date and time custom values
'meta_query' => [
'date_' => [
'key' => 'start_date',
'compare' => 'EXISTS',
],
'time_' => [
'key' => 'start_time',
'compare' => 'EXISTS',
],
],