Skip to content

Instantly share code, notes, and snippets.

View theukedge's full-sized avatar

Dave Clements theukedge

View GitHub Profile
@theukedge
theukedge / gist:6563430
Last active December 23, 2015 01:59
Show first n paragraphs - WordPress
View gist:6563430
<?php
// FILTER POST CONTENT - SHOWS FIRST N PARAGRAPHS
function filter_content_n_paragraphs( $content ) {
$stopat = 2; // how many paragraphs you want to display (n)
$paragraphno = $stopat - 1; // computers start at 0
// conditions to meet for filtering content
if( !is_user_logged_in() ) {
View gist:6563864
<?php
function set_email_to_pardot_cookie() {
setcookie( 'email-to-pardot', 1, strtotime( '+30000 days' ), COOKIEPATH, COOKIE_DOMAIN, false );
}
add_action( 'gform_after_submission_1', 'set_email_to_pardot_cookie' );
View gist:6563869
<?php
// FILTER POST CONTENT FOR PARDOT
function filter_post_content_pardot($content) {
if( get_post_meta( get_the_ID(), 'pardot_protected', true ) == 'protected' && !is_user_logged_in() && !isset( $_COOKIE['email-to-pardot'] ) ) {
return gravity_form(1, false, false, false) . '<p>This article is only available to subscribers to our newsletter. You may subscribe using the form above.</p>';
}
else {
return $content;
View gist:6563876
<?php
function chain_select_shortcode( $atts ) {
extract( shortcode_atts( array( 'tax' => 'category', 'level' => 1, 'titles' => array( 'Please select…' ), 'labels' => '', 'btn_text' => 'Submit', 'exclude' => '', 'count' => 1 ), $atts ) );
return chainselect_getcategories( $tax, $level, explode( ', ', $titles ), explode( ', ', $labels ), $btn_text, $exclude, $count );
}
add_shortcode( 'ajax_chain_select', 'chain_select_shortcode' );
View gist:6565712
<!-- Load time: <?php timer_stop( 1, 3 ); ?> seconds to this point. -->
View gist:6565728
<?php
function set_form_1_complete_cookie() {
setcookie( 'form-1-complete', 1, strtotime( '+30 days' ), COOKIEPATH, COOKIE_DOMAIN, false, false );
}
add_action( 'gform_after_submission_1', 'set_form_1_complete_cookie' );
View gist:6565735
<?php
function restrict_post_content_form_1($content) {
if( get_post_meta( get_the_ID(), 'protected', true ) == 'yes' && !is_user_logged_in() && !isset( $_COOKIE['form-1-complete'] ) ) {
return gravity_form(1, false, false, false) . '<p>This article is only available to subscribers to our newsletter. You may subscribe using the form above.</p>';
}
else {
return $content;
}
}
View gist:6565740
<?php
// LOGOUT LINK IN MENU
function diww_menu_logout_link( $nav, $args ) {
$logoutlink = '<li><a href="'.wp_logout_url().'">Logout</a></li>';
if( $args->menu->term_id == '5' ) {
return $nav.$logoutlink ;
} else {
return $nav;
View gist:6565746
<?php
// LOGOUT LINK IN MENU
function diww_menu_logout_link( $nav, $args ) {
$logoutlink = '<li><a href="'.wp_logout_url().'">Logout</a></li>';
if( $args->theme_location == 'primary' ) {
return $nav.$logoutlink ;
} else {
return $nav;
View gist:6565757
<?php
$logoutlink = '<li><a href="'.wp_logout_url( home_url() ).'">Logout</a></li>'; // redirect to home page
$logoutlink = '<li><a href="'.wp_logout_url( get_permalink() ).'">Logout</a></li>'; // stay on same page
$logoutlink = '<li><a href="'.wp_logout_url( 'http://www.doitwithwp.com/about/' ).'">Logout</a></li>'; // go to specific URL