Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / create_user.sql
Last active February 13, 2016 19:41
SQL - create new user
INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Your Name', '[email protected]', 'http://www.test.com/', '2011-06-07 00:00:00', '', '0', 'Your Name');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');
@twentyfortysix
twentyfortysix / register_feed.php
Last active February 13, 2016 19:43
WP - create custom json feed
// register json feed
class custom_feed {
public $feed = 'json';
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
@twentyfortysix
twentyfortysix / umount.shell
Last active February 13, 2016 19:43
Transmit - MAC/SHELL - force to unmount all transmit connections
pkill -9 -f 'Transmit Disk'
@twentyfortysix
twentyfortysix / NO-png-bmp.php
Last active February 13, 2016 19:45
WP - disable png and other big files to upload
/** prevent uploading of .bmp files. */
add_filter('upload_mimes', function(array $mimes)
{
unset($mimes['bmp']);
unset($mimes['png']);
return $mimes;
});