2014 Usefull Code Snippet for WordPress 3.8.2

WordPress is a very powerful CMS, used by personal, professional bloggers and large-scale international media. This proves that wordpress is a big part of the internet. WordPress is written in PHP and MySQL database and released as open source. Therefore, the development of wordpress is very fast.

Up to date, wordpress has been used by approximately 77 million domains worldwide, and continues to grow. And has reached version 3.8.2. My first time using wordpress version 2.0 and was very impressed with its features. Moreover, there is support for plugins, so we can add features as needed.

WordPress is very flexible to be developed, because the wordpress source code can be accessed by anyone, there is no section in the codes are encryption. You can add a line of code or 100 lines of code in the wordpress core. But, remember you have to know 100 % what kind of wordpress.

Here are some code snippets that you can add on wordpress. The goal for wordpress works according to what you want. Well, everyone is different purpose, right?

Redirect Succesfull Registration on WordPress


Source

Upload Media from Front-End

This script will help your visitors to send files or media from front-end of your web.

Jquery Snippet to Activate Arrow of Keyboard (Next and Prev Post)


Place it on the header.php of your theme
Source

Remove WordPress Logo in WP-Login.php


Make your wordpress more private, and hide or change WP logo.
Source

Comment Length Must Be More Than XX Char


This script will provide filters: long comment should be more than xx. You can determine how long you wanted. The goal is to ensure that the comments given more qualified visitors
Source

Thanks for +Kevin Chard with your usefull code snippet.

Change The Password Protected Text In WordPress

‘.antispambot( $adminEmail ).’
Source

Add Custom Colors in Wp Editor


Source

Get SRC Image in Thumbnail

<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>

 Display Most Commented Post

function wpb_most_commented_posts() { 
// start output buffering
ob_start();
?>
<ul class="most-commented">
<?php 
// Run WP_Query
// change posts_per_page value to limit the number of posts
$query = new WP_Query('orderby=comment_count&posts_per_page=10'); 

//begin loop
while ($query->have_posts()) : $query->the_post(); ?>

<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <span class="wpb-comment-count"><?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></span></li>
<?php endwhile; 
// end loop
?>
</ul>
<?php

// Turn off output buffering
 $output = ob_get_clean(); 

//Return output 
return $output; 
}
// Create shortcode
add_shortcode('wpb_most_commented', 'wpb_most_commented_posts'); 

//Enable shortcode execution in text widgets
add_filter('widget_text', 'do_shortcode');

Then show it on front-end

<?php the_post_thumbnail(array(40,40)); ?>

Dont forget to styling your code

.most-commented li { 
border-bottom:1px solid #eee; 
padding-bottom:3px; 
} 
.most-commented li :after { 
clear:both;
} 
.most-commented img { 
padding:3px;
margin:3px;
float:left;
}
.wpb_comment_count a, .wpb_comment_count a:active, .wpb_comment_count a:visited, .wpb_comment_count a:hover { 
color:#FFF;
}

 Source

Add Lorem Ipsum Text in Page

add_filter ('the_content', 'emw_custom_filter_the_content');
 
/**
* Returns Lorem Ipsum text for blank pages
* 
* @param string $content - the page's current contents
* @return string
*/
function emw_custom_filter_the_content ($content) {
    if ($content == '') {
        if ($c = get_transient ('lipsum'))
            return $c;
        $content = wp_remote_get ('http://www.lipsum.com/feed/json');
        if (!is_wp_error($content)) {
            $content = json_decode (str_replace ("\n", '</p><p>', $content['body']));
            $content = '<p>'.$content->feed->lipsum.'</p>';
            set_transient ('lipsum', $content, 3600); // Cache the text for one hour
            return $content;
        }
    } else
        return $content;
}

Remove Width & Height from Image Inserted Using Media Uploader

add_filter( 'post_thumbnail_html', 'delete_image_width_height', 20 );
add_filter( 'image_send_to_editor', 'delete_image_width_height', 20 );
 
function delete_image_width_height( $html ) {
   $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
   return $html;
}

Source

2 thoughts on “2014 Usefull Code Snippet for WordPress 3.8.2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.