Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / wp_config_memory_allocation.php
Created February 18, 2014 11:47
WP Memory allocation
define('WP_MEMORY_LIMIT', '128M');
@yanknudtskov
yanknudtskov / redirect-on-login.php
Created February 19, 2014 22:49
Redirect a User After Login You can redirect users who login to your site to another URL based on their role using this snippet. Just add it to your functions.php file:
<?php
function redirect_user_on_role()
{
//retrieve current user info
global $current_user; get_currentuserinfo();
//If login user role is Subscriber
if ($current_user->user_level == 0)
{
wp_redirect( home_url() ); exit;
}
<?php
add_filter( 'tgmsp_caption_output', 'tgm_soliloquy_custom_html', 10, 4 );
function tgm_soliloquy_custom_html( $html, $id, $image, $i ) {
// If the ID doesn't match the one we want to modify, return the default HTML output. Change 324 to your slider ID.
if ( '324' !== $id )
return $html;
// Append custom code output of the caption to do whatever. $i is the number of the slide.
$html .= '<div class="my-custom-class"><p>My custom stuff!</p></div>';
@yanknudtskov
yanknudtskov / random_redirect.js
Created March 14, 2014 18:39
Redirect to random page using JS and jQuery
var urlArray = ['http://url1.com', 'http://url2.com', 'http://url3.com'];
var random_url;
var redirect_after_milliseconds = 2000;
$(function() {
random_url = urlArray[Math.floor(Math.random() * urlArray.length)];
setTimeout(function() {
// similar behavior as an HTTP redirect
window.location.replace(random_url)
@yanknudtskov
yanknudtskov / cf7-email-population.php
Created April 1, 2014 14:36
Code to change pre-set the e-mail field for a contactform7. Remember to: * Replace CONTACT_FORM_7_SHORTCODEwith the appropriate CF7 shortcode * Replace contact-form-7-email-field-class-selector with the appropriate class/id selector for the CF7 e-mail field
<?php if ( is_user_logged_in() ) : ?>
<?php global $current_user;
get_currentuserinfo();
?>
/* INSERT ContactForm7 ShortCode HERE */
<?php echo do_shortcode( 'CONTACT_FORM_7_SHORTCODE' ); ?>
<script> $(function() {
@yanknudtskov
yanknudtskov / move-admin-bar-to-bottom.php
Created April 9, 2014 13:32
Move the admin bar to the botto
function fb_move_admin_bar() {
echo '
';
}
// on backend area
add_action( 'admin_head', 'fb_move_admin_bar' );
@yanknudtskov
yanknudtskov / add-featured-image-to-wordpress-feeds.php
Created April 9, 2014 13:34
Add Featured Image to WordPress feeds
@yanknudtskov
yanknudtskov / change-default-theme.php
Created April 21, 2014 18:07
Change the default theme for WordPress
define( 'WP_DEFAULT_THEME', 'default-theme-folder-name' );
function my_redirect( $to, $requested, $user ){
if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied
return $to;
}
$regtime = strtotime($user->user_registered);
$now = strtotime("now");
$diff = $now - $regtime;
$hours = $diff / 60 / 60;
if( $hours < 48 ){
return "/somepage/"; // it's been less than 48 hours, redirect to message.
@yanknudtskov
yanknudtskov / get_image_tag_from_acf_image_object.php
Created May 23, 2014 11:32
Get image tag through an Advanced Custom Field Image Object with parameters.
<?php
function va_string_is_null_or_empty($string) {
return (!isset($string) || trim($string) === '');
}
function va_get_acf_imagetag_from_image_object( $image_object_fieldname, $image_size = '', $is_option_field = false, $is_sub_field = false ) {
$image_size = '';
$image_width = '';
$image_height = '';