Sunday, January 20, 2013

How to remove the “/blog/” from your WordPress Multisite url slug

Go to /wp-admin/options-permalink.php page and remove $blog_prefix = '/'; and save the page.

Tuesday, January 15, 2013

Enable widgets for editor role

$role_object = get_role( 'editor' );
//print_r($role_objec);
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );

function custom_admin_menu() {

$user = new WP_User(get_current_user_id());
if (!empty( $user->roles) && is_array($user->roles)) {
foreach ($user->roles as $role)
$role = $role;
}

if($role == "editor") {
remove_submenu_page( 'themes.php', 'themes.php' );
remove_submenu_page( 'themes.php', 'nav-menus.php' );
remove_submenu_page( 'themes.php', 'theme_options' );
remove_submenu_page( 'themes.php', 'custom-header' );
}
}

add_action('admin_menu', 'custom_admin_menu', 11);


Thursday, January 3, 2013

WordPress pagination without plugins

global $wp_query; 
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo '<div class="page_nav">';
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => 'Prev',
'next_text' => 'Next'
));
echo '</div>';
}

Wednesday, January 2, 2013

Facebook open graph snippet to set default image

function diww_facebook_image() {
                echo '<meta property="fb:admins" content="ADMIN_ID" />';
                echo '<meta property="og:title" content="' . get_the_title() . '" />';
                echo '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />';
        global $post;
        if ( is_singular() ) { // only if a single post or page
                echo '<meta property="og:type" content="article" />';
                echo '<meta property="og:url" content="' . get_permalink() . '" />';
        if (has_post_thumbnail( $post->ID )) { // use featured image if there is one
                $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
                echo '<meta property="og:image" content="' . esc_attr( $feat_image[0] ) . '" />';
         }else{ // use site logo in case no featured image
                echo '<meta property="og:image" content="http://yourdomain.com/logo.png" />';
         }
        }
        if ( is_home() ) { // for homepage only
                echo '<meta property="og:type" content="website" />';
                echo '<meta property="og:url" content="' . get_bloginfo('url') . '" />';
                echo '<meta property="og:image" content="http://yourdomain.com/logo.png" />';
        }
}
add_action( 'wp_head', 'diww_facebook_image' );