Skip to content

Instantly share code, notes, and snippets.

//Anti-Spam Email Shortcode
//Use this shortcode [email][email protected][/email]
function protect_email_address( $atts , $content=null ) {
for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';';
return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>';
}
add_shortcode('email', 'protect_email_address');
//Screenshot Snap Shortcode
// Usage: [snap url="http://wordpress.com" alt="WordPress" w="400" h="300" title="WordPress" descr='WordPress is awesome,']
function ni_screenshot($atts, $content = null) {
extract(shortcode_atts(array(
"snap" => 'http://s.wordpress.com/mshots/v1/',
"url" => 'http://training.ithemes.com',
"w" => '400',
"h" => '300',
"title" => 'Site Title',
// Removes PRIVATE from Private Page Titles
function remove_private_prefix($title) {
$title = str_replace(
'Private:',
'',
$title);
return $title;
}
add_filter('the_title','remove_private_prefix');
// Make Private Pages show in Parent Page List
function bla_handle_privates_adding( $args ) {
if ( ! current_user_can( 'read_private_pages' ) ) {
return $args;
}
$defaults = array( 'post_status' => 'publish,private' );
return wp_parse_args( $args, $defaults );
}
add_filter( 'wp_page_menu_args', 'bla_handle_privates_adding' );
// Creates Login Shortcode
// Shortcode Usage: [loginform redirect="http://my-redirect-url.com"]
function pippin_login_form_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'redirect' => ''
), $atts ) );
if (!is_user_logged_in()) {
// Limit Post Title Size
function maxTitleLength($title) {
global $post;
$title = $post->post_title;
if (str_word_count($title) >= 10)
wp_die( __('Error: your post title is over the maximum word count.'));
}
add_action('publish_post','maxTitleLength');
//Limit Search to Post Titles Only
function __search_by_title_only( $search, &$wp_query )
{
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
//Search in the Navbar
add_filter('wp_nav_menu_NAVBAR-NAME_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li class="nav-search-form">' . $searchform . '</li>';