Skip to content

Instantly share code, notes, and snippets.

View Bobeta's full-sized avatar

Moris Pasic Bobeta

View GitHub Profile
@Bobeta
Bobeta / functions.php
Last active October 9, 2016 16:29
Disable The Admin Bar in WP
<?php
// Remove the admin bar from the front end
add_filter( 'show_admin_bar', '__return_false' );
@Bobeta
Bobeta / functions.php
Last active October 9, 2016 16:28
Show post thumbnails in WP RSS feed
<?php
// Put post thumbnails into rss feed
function wpfme_feed_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '' . $content;
}
return $content;
}
@Bobeta
Bobeta / functions.php
Last active October 9, 2016 18:53
Show WP Popular Posts without plugin.
<?php
// Add this in your functions file
function count_post_visits() {
if( is_single() ) {
global $post;
$views = get_post_meta( $post->ID, 'my_post_viewed', true );
if( $views == '' ) {
update_post_meta( $post->ID, 'my_post_viewed', '1' );
} else {
$views_no = intval( $views );
@Bobeta
Bobeta / lightbox-to-all-imgs.php
Last active October 9, 2016 16:30
WP Add rel=”lightbox” to all images embedded in a post
<?php
// Add lightbox to all images embedded in a post
add_filter('the_content', 'my_addlightboxrel');
function my_addlightboxrel($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;