Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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('protectmy@email.com', 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 / 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 / domain_based_body_class.php
Created April 14, 2013 18:08
WP: dynamically add CSS class to body tag based on website domain. Useful when your using the same theme on all sites, but want to alter some styling (e.g. background) on some sites.
<?php
// Add custom CSS class to <body> tag
add_filter('body_class','intw_body_class');
function intw_body_class($classes) {
$url = get_bloginfo('url');
if( ($url == 'http://siteA.com') || ($url == 'http://devserver.com/siteA') ) {
$classes[] = 'siteA';
return $classes;
} elseif ( ($url == 'http://siteB.com') || ($url == 'http://devserver.com/siteB') ) {
@intelliweb
intelliweb / add_shortcode.php
Last active January 3, 2018 15:10
WP: add shortcode. Replace SHORTCODE_TAG with whatever text you want to use in the shortcode.
<?php
// Shortcode: [SHORTCODE_TAG]
add_shortcode('SHORTCODE_TAG', 'intw_shortcode_SHORTCODE_TAG');
function intw_shortcode_SHORTCODE_TAG($atts) {
extract( shortcode_atts( array(
'att1' => 'DEFAULT_VALUE',
'att2' => 'DEFAULT_VALUE',
), $atts ) );
ob_start(); ?>
@intelliweb
intelliweb / style_input_placeholder.css
Last active December 16, 2015 05:39
CSS: style form input placeholder
input::-webkit-input-placeholder { /* Webkit - Yes, double :: is correct! */
color: #eaeaea;
}
input:-moz-placeholder { /* Firefox 4-18 */
color: #eaeaea;
}
input::-moz-placeholder{ /* Firefox 19+ */
color: #eaeaea;
}
input:-ms-input-placeholder { /* IE 10+ */
@intelliweb
intelliweb / gf_inline_submit.css
Created April 15, 2013 05:02
WP: inline submit button using Gravity Forms. Handy when doing inline opt-in form.
.gform_footer.top_label {
float: right;
margin: -45px 0 0 0;
}
@intelliweb
intelliweb / builder_blank_content_template.php
Created June 7, 2013 16:58
Builder blank page content template using the builder_layout_engine_render_content hook
<?php
/*Template Name: Blank */
function render_content() {
//CODE and INFORMATION GOES IN THIS FUNCTION
}
add_action( 'builder_layout_engine_render_content', 'render_content' );