WordPress Plugin Tips

May 2, 2013   //   by kdecom   //   wordpress  //  No Comments

WordPress Plugin Tips

 

wordpress-plugin-tips

Specially this post is all about to make wordpress developer life easy and improve code base.

How to Use post_content with well formatted

If you are a developer and you are working on a plugin or custom development. So many times it happens to be a you got the post content but when you echo out that content its not formatted.

In my example i was working with event plugin and i got the post_content but when i did echo out that content there was no formatting.  Just use the filter called the_content and you will get the content with well formatted.

Here is my solution:-

$content = $post->post_content;
$content = apply_filters('the_content', $content);

echo $content;

 

How to limit the meta box on certain page only.

global $post;
$screens = array('post', 'page');
    foreach ($screens as $screen) {
        if($screen == "page") {
            if($post->ID == '2' || $post->ID == 7) {
            add_meta_box('rhm_service_sectionid', __('Quote Box', 'rhm_service_textdomain'), 'rhm_service_inner_custom_box', $screen);
            }
        } else {
            add_meta_box('rhm_service_sectionid', __('Quote Box', 'rhm_service_textdomain'), 'rhm_service_inner_custom_box', $screen);
        }
}

How to add Category or tags within custom post type in WordPress

add_action('init', 'custome_post_type_add_default_boxes');

function custome_post_type_add_default_boxes() {
    register_taxonomy_for_object_type('category', 'your_custom_post_type');
    register_taxonomy_for_object_type('post_tag', 'your_custom_post_type');
}

Leave a comment

css.php