Monday, February 25, 2013

Clean up your WordPress database from weird characters

Here is a query that you can run in order to clean your database from weird characters
 
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…');

UPDATE wp_comments SET comment_content = REPLACE(comment_content, '“', '“');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '”', '”');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '’', '’');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '‘', '‘');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '—', '–');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '–', '—');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '•', '-');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '…', '…');
 

Tuesday, February 19, 2013

How to remove shortcode from home but not from the entire blog

Just paste the code to your function.php to remove the shortcode value from index.php or home.php but not from the rest of your template
function wpc_no_shortcode_home($content) {
    if ( is_home() ) {
      $content = strip_shortcodes( $content ); 
   }    
return $content;  
}  
add_filter('the_content', 'wpc_no_shortcode_home');

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' );

Wednesday, November 28, 2012

use the get_bookmarks() method

<?php $links = get_bookmarks( array(
'orderby' => 'link_id',
'order' => 'ASC',
));
//print_r($links);
// Loop through each bookmark and display the formatted output
foreach ( $links as $link ) {
echo '<li>';
echo '<strong>'.$link->link_name.'</strong>';
echo '<br />';
echo '<a href="'.$link->link_url.'" target="_blank">';
echo $link->link_url.'</a>';
echo '<br />';
echo $link->link_description;
echo '</li>';
} ?>