Skip to content

Instantly share code, notes, and snippets.

Avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / redirect-on-login.php
Created Feb 19, 2014
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:
View redirect-on-login.php
<?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;
}
View gist:9365414
<?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 Mar 14, 2014
Redirect to random page using JS and jQuery
View random_redirect.js
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 Apr 1, 2014
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
View cf7-email-population.php
<?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() {
View add-featured-image-to-wordpress-feeds.php
@yanknudtskov
yanknudtskov / move-admin-bar-to-bottom.php
Created Apr 9, 2014
Move the admin bar to the botto
View move-admin-bar-to-bottom.php
function fb_move_admin_bar() {
echo '
';
}
// on backend area
add_action( 'admin_head', 'fb_move_admin_bar' );
@yanknudtskov
yanknudtskov / change-default-theme.php
Created Apr 21, 2014
Change the default theme for WordPress
View change-default-theme.php
define( 'WP_DEFAULT_THEME', 'default-theme-folder-name' );
View redirect-user-on-first-login.php
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
Get image tag through an Advanced Custom Field Image Object with parameters.
View get_image_tag_from_acf_image_object.php
<?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 = '';
You can’t perform that action at this time.