Skip to content

Instantly share code, notes, and snippets.

@intelliweb
intelliweb / autoset_featured_image.php
Created April 10, 2013 17:22
WP: automatically set the first image in post as the featured image if a featured image was not set manually
@intelliweb
intelliweb / encode_email.php
Last active December 16, 2015 00:39
WP: encodes email address by converting each character into HTML entities to help protect against spambots
<?php
// WordPress function that encodes an email address (and adds mailto: link)
echo antispambot('[email protected]', 1);
?>
<?php
// Shortcode to encode email address in a mailto: link
function protect_email_address( $atts , $content=null ) {
for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';';
@intelliweb
intelliweb / google_analytics_non_admins.php
Created April 9, 2013 03:33
WP: add Google Analytics code for non- logged-in admins (does NOT track logged-in admins)
<?php
function intw_head() {
if ( !current_user_can('administrator') ) { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'example.com']);
_gaq.push(['_trackPageview']);
(function() {
@intelliweb
intelliweb / gf_move_descriptions.php
Created April 9, 2013 03:30
Gravity Forms: Move field descriptions above fields. Make sure to place this snippet AFTER where jQuery is enqueued (right before the </ head> tag is good). The description CSS may need to be tweaked to change margins, padding depending on theme and preferences. Source: http://www.gravityhelp.com/forums/topic/request-setting-to-place-field-descr…
<?php
function intw_gf_sublabels() {
if( is_page(39) ) { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.ginput_complex label').each(function(i,e){
sublabel = jQuery('<label>').append(jQuery(e).clone()).remove().html();
jQuery(e).siblings().after(sublabel);
jQuery(e).remove();
@intelliweb
intelliweb / remove_admin_menu_items.php
Created April 9, 2013 03:09
WP: remove menu items from WP admin
<?php
function intw_remove_menus() {
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login != 'webmaster') {
$restricted = array(
__('Posts'),
__('Links'),
@intelliweb
intelliweb / related_posts_category.php
Created April 9, 2013 03:05
WP: related posts by category
<?php
class Intw_User_Caps {
// Add our filters
function Intw_User_Caps(){
add_filter( 'editable_roles', array(&$this, 'editable_roles'));
add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
}
@intelliweb
intelliweb / is_tree.php
Last active March 1, 2021 20:57
WP: is_tree() function to check if the current page is the page or a sub page of the page ID specified. Can be used as conditional tag with Widget Logic. Source: http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
<?php
// This function will return true if we are looking at the page in question or one of its sub pages
function is_tree( $pid ) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
if ( is_page($pid) )
return TRUE; // we're at the page or at a sub page
$anc = get_post_ancestors( $post->ID );
@intelliweb
intelliweb / builder_modify_widget_title_wrappers.php
Created March 21, 2013 02:08
Builder: Change default widget title HTML wrapper. How to replace H4 tags around widget titles
<?php
// Modify default widget wrappers
add_filter( 'builder_filter_register_sidebar_options', 'intw_modify_widget_wrappers' );
function intw_modify_widget_wrappers( $options ) {
$options['before_title'] = '<div class="widget-title">';
$options['after_title'] = '</div>';
return $options;
}
?>
@intelliweb
intelliweb / before_after_body.php
Created March 21, 2013 02:05
Builder: Add code just after <body> and just before </body>
<?php
// Hook right after opening <body> tag
add_action('builder_layout_engine_render_header', 'intw_add_after_opening_body', 20 );
function intw_add_after_opening_body() { ?>
HTML code that you want just after the opening body tag should be placed here
<?php }
// Hook right before closing </body> tag
add_action('builder_finish', 'intw_add_before_closing_body', 0 );
function intw_add_before_closing_body() { ?>