Some best WordPress Hacks for theme developer

there are many wordpress theme deverlopers who are looking for wordpress hacks for theme developer. we have best collection of wordpress hacks for theme developer. Some best WordPress Hacks for theme developer.

wordpress hacks for theme developer

 wordpress hacks for theme developer
wordpress hacks for theme developer

WordPress themes market has grown incredibly. Due to lot of amazing new functionality an synchronization with all social sites.

1. Create TinyURLs with your wordpress site
Open your single.php file and paste the following in the loop:


<?php
echo 'Tiny Url for this post: <a href="'.bloginfo('siteurl').'?p=.'$post->ID.'">'.bloginfo('siteurl').'?p=.'$post->ID.'</a>'
?>

2. Use The Loop To Create An “Archive” Page Template

Create the php page called archive.php and create archive page through wordpress admin and select the archive page template from sidebar option.

In archive.php file you can following code:

<?php
/*
Template Name: Archives
*/
?>

<?php get_header(); ?>

<h2><?php $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts); ?>
<h2><?php echo $numposts.' recipes published since October 06, 2008'; ?>
</h2>

<ul id="archive-list">
<?php
$myposts = get_posts('numberposts=-1&');
foreach($myposts as $post) : ?>
<li><?php the_time('m/d/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

3. Create A “Share the article with Facebook” Button
Use the following code in your loop where you want show the facebook share button.

<a href="http://www.facebook.com/sharer.php?u=<?php get_permalink();?>&t=<?php the_title(); ?>" target="blank">Share on Facebook</a>

4. Use More Than One Loop On A Page, Without Printing Duplicate Posts

If you want to use two query post in page or post. you can use following code:

<?php
query_posts('showposts=8');
$ids = array();
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
the_content();
endwhile;
?>

<?php
query_posts(array('post__not_in' => $ids));
while (have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>

5. Insert Ads After The First Post
If you want show the ad after first post then use the following code:

<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 2) : ?>
//Paste your ad code here
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php else : ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

There are so many wordpress tricks and hack you can found in this website. Search more.

How to remove curly quotes from WordPress post

While doing the copy and paste from any website is always problem. While coping the code. curly quotes come and you want to convert that into straight quotes. Some time you want to remove curly quotes from WordPress post title or body.

How to remove curly quotes from WordPress post Title and body.

Here we have given following code which can be useful. The apostrophe should be straight not curly in WordPress.

Just Open your functions.php file from your theme folder. If you did not created functions.php file then you can paste this code in your header.php file.

remove_filter('comment_text', 'wptexturize');
remove_filter('the_title', 'wptexturize');
remove_filter('the_content', 'wptexturize');

This will solve your problem.

How to remove curly quotes and use straight quotes then use following code.

function removesmartquotes($content) {
$content = str_replace('&#8220;', '&quot;', $content);
$content = str_replace('&#8221;', '&quot;', $content);
$content = str_replace('&#8216;', '&#39;', $content);
$content = str_replace('&#8217;', '&#39;', $content);

return $content;
}
add_filter('the_content', 'removesmartquotes');
add_filter('comment_text', 'removesmartquotes');

More reference

code snippets which is most useful in functions.php, wordpress
code snippets which is most useful in functions.php, wordpress

In wordpress – wp-includes/default-filters.php file, we have following list of filters which we can override.

/ Display filters
//add_filter('the_title', 'wptexturize');
add_filter('the_title', 'convert_chars');
add_filter('the_title', 'trim');
 
//add_filter('the_content', 'wptexturize');
add_filter('the_content', 'convert_smilies');
add_filter('the_content', 'convert_chars');
add_filter('the_content', 'wpautop');
add_filter('the_content', 'prepend_attachment');
 
//add_filter('the_excerpt', 'wptexturize');
add_filter('the_excerpt', 'convert_smilies');
add_filter('the_excerpt', 'convert_chars');
add_filter('the_excerpt', 'wpautop');
add_filter('get_the_excerpt', 'wp_trim_excerpt');
 
//add_filter('comment_text', 'wptexturize');
add_filter('comment_text', 'convert_chars');
add_filter('comment_text', 'make_clickable', 9);
add_filter('comment_text', 'force_balance_tags', 25);
add_filter('comment_text', 'convert_smilies', 20);
add_filter('comment_text', 'wpautop', 30);
 
add_filter('comment_excerpt', 'convert_chars');
 
//add_filter('list_cats', 'wptexturize');
//add_filter('single_post_title', 'wptexturize');

 

 

How to exclude images from wordpress post

In one of our project, we got the requirement of exclude images from wordpress post while showing post. We have written code for excluding the image from Post.

How to exclude images from wordpress post

you can use following code in functions.php file or you can use in single.php file. These files you can find in wordpress theme folder.

For changing the code you can use the wordpress admin -> editor section.

Above line I added in showing post without image.


<?php
$FormatedContent = content_with_formatting();
$content = the_content();
$postWithoutImage = preg_replace('/<img[^>]+./’,'' $FormatedContent);
echo $postWithoutImage;
?>

In above code we are checking the image tag and replacing with none.

If you want to find all images from post then Use following command.

preg_match_all('/<img[^>]+>/i',YOUR_text, $result);

You need to add following function in your function.php file(Theme files).

function content_with_formatting($more_link_text = ‘(more…)’, $stripteaser = 0, $more_file = ”)
{
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]>’, $content);
return $content;
}

If you want to Hide all images using CSS then use following code

img{
display:none;
}

Just put above code in your style.css file.

Fetch the wordpress post paragraph number wise

In this article we given code for Fetch the wordpress post paragraph number wise. created One function for fetching the wordpress post as per p tag number.

Fetch the wordpress post paragraph number wise

# You can Use this function for showing

function paragraph_show($paragraph_number, $post_content){
$show_after_paragraph_tag = 1;
$paragraph_number= $paragraph_number - 1;
//echo $paragraph_number;
$content = apply_filters('the_content', $post_content);

if(substr_count($content, '

') > $show_after_paragraph_tag)
//echo substr_count($content, '

');

{
$contents = explode("

", $content);
$p_count = 0;
foreach($contents as $content)
{
//echo $p_count;
if($paragraph_number == $p_count){
echo $content;
}

$p_count++;
}
}
}

We can use this function like this.

In while loop you can use or paste following code

#This will show the first paragraph of post.
post_content);