Category: WordPress

Hosting Recommendations

I keep a document of hosting recommendations to share with clients. This is one of those things that changes often, as companies come and go, get bought and sold, etc, so I’m simply going to link to the Google Doc that I share with clients.

Move content directory for additional security

Add this to wp-config-sample.php after an update, or add it to wp-config.php. Just after the prefix code. Replace “newdir” with the name of your new directory.

/**
 * Move content directory for additional security
 */
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/newdir' );
define( 'WP_CONTENT_URL', 'http://'.$_SERVER['SERVER_NAME'].'/newdir' );

Bootstrap for dynamic widget widths

jQuery(document).ready(function($) {	
    var numwidgets = $('.header-widget-area section.widget').length;
    $('.header-widget-area').addClass('cols-'+numwidgets);
    var cols = 12/numwidgets;
    $('.header-widget-area section.widget').addClass('col-sm-'+cols);
    $('.header-widget-area section.widget').addClass('col-xs-12');
});

Contact Form 7 and Bluehost

Had some issues setting up a site developed by other developers. Aaaaaand this is why Gravity Forms is better. But, anyway, the solution was simple enough: http://wordpress.org/support/topic/contact-form-7-not-working-6

Update: Come to find the same issue with Gravity Forms on a Liquid Web VPS. I realized that (duh) this would always be an issue for clients who use a remote mail exchanger, as the server won’t even look outside itself if it thinks the mail exchanger is local. So, the steps for a cPanel host (which is most of my clients):

cPanel->Mail->MX Entry->Choose Domain-> Find MX Record and look for “Email Routing”->Change to Remote Exchanger.

Of course, ONLY do this for sites that aren’t using the web host to collect mail!

Getting an attachment from a URL

Specifically, to get a different size of the image.

        $attachment_id = get_attachment_id_from_src($solutions_metabox->get_the_value('image'));
        $image_url = wp_get_attachment_image_src($attachment_id,'solutions');

WPAlchemy repeating fileds and the wp_editor()

I may have something working. I’m still doing some testing, but I think the problem lies here:
” $editor_id (string) (required) HTML id attribute value for the textarea and TinyMCE. (may only contain lower-case letters)” (http://codex.wordpress.org/Function_Reference/wp_editor)

When you try to pass $mb->get_the_name(), it inputs all kinds of brackets and such, which are disallowed characters. Here’s where I’m at:

https://gist.github.com/foxydot/9075575.js

Using sanitize_key removes those illegal characters. Adding ‘textarea_name’=>$mb->get_the_name() to the settings array re-targets the input to that hidden textbox.

I’m using Extract Mode (I always do, for searchability) and so far it seems to be working.

Gravity forms CSS tricks

http://kevinshoffner.com/wordpress/tipstricks/custom-css-gravity-forms/

Here is a quick list of all of the built-in classes:

Checkboxes and Lists Fields

gf_list_2col

= 2 columned List

gf_list_3col

= 3 columned List

gf_list_4col

= 4 columned

gf_list_5col

= 5 columned

Two Columns of Text Fields side by side

gf_left_half

= The left column

gf_right_half

= The right column

Three Columns side by side

gf_left_third

= Left column

gf_middle_third

= Middle column

gf_right_third

= Right column

Some other miscellaneous styles

gf_scroll_text

= Gets a scroll box into place, for those long sections where you need to give your visitor lots of information
scrolling-text

gf_hide_ampm

= If you want to hide the AM/PM portion of the Time field

gf_list_inline

= Simpliar to the above gf_list classes, but just show up next to each other using the amount of space the content can use on each line, instead of making it fit within 2,3,4,5 columns.

gf_hide_charleft

= Do not display the amount of characters left / character counter

I’ve not found a great use for these, but they are available:

gf_list_height_25

= 25 pixels between list items

gf_list_height_50

= 50 pixels between list items

gf_list_height_75

= 75 pixels between list items

gf_list_height_100

= 100 pixels between list items

gf_list_height_125

= 125 pixels between list items

gf_list_height_150

= 150 pixels between list items

Genesis Widget Formatting

Genesis has a pretty cool filter available to override the default settings for a widget area. You can use this to filter all of the widget area layouts:

function msdlab_register_sidebar_defaults($args){
    $args = array(
            'before_widget' => genesis_markup( array(
                'html5' => '<section id="%1$s" class="widget %2$s">',
                'xhtml' => '<div id="%1$s" class="widget %2$s">',
                'echo'  => false,
            ) ),
            'after_widget'  => genesis_markup( array(
                'html5' => '</div></section>' . "\n",
                'xhtml' => '</div></div>' . "\n",
                'echo'  => false
            ) ),
            'before_title'  => '<h4 class="widget-title widgettitle">',
            'after_title'   => genesis_markup( array(
                'html5' => '</h4>'."\n".'<div class="widget-wrap">',
                'xhtml' => '</h4>'."\n".'<div class="widget-wrap">',
                'echo'  => false,
            ) ),
        );
   return $args;
}

The issue comes when you try to activate it. Because the default widget areas are registered before the filter is defined, it won’t work unless you do something like so:

remove_action( 'genesis_setup', 'genesis_register_default_widget_areas' ); //remove initial setup of default widgets
add_action( 'after_setup_theme', 'genesis_register_default_widget_areas' ); //move them to AFTER the theme files are loaded
add_filter('genesis_register_sidebar_defaults','msdlab_register_sidebar_defaults'); //and here's the filter

Genesis 2 CPT Archive Settings

This is pretty cool.

Basically, you can add backend editing to the CPT archive with something like this:

function register_snippet_post_type(){
  
  // custom post type arguments
	$post_type_args = array(
		'label'		=> __( 'Snippet' ),
		'description'	=> __( 'Display code snippets' ),
		'public'	=> true,
		'show_ui'	=> true,
		'show_in_menu'	=> true,
		'has_archive'	=> true,
		'supports'	=> array( 'title', 'editor', 'genesis-cpt-archives-settings' )
	);
	
	// register the 'snippet' post type
	register_post_type( 'snippet', $post_type_args );
	
}