Wordpress tricks

Home/Wordpress tricks

wordpress tricks, tips, code snippets, wordpress plugins, plugin development, useful functions in wordpress, template tags and customization, frontend uploader for wordpress posts

5 01, 2017

5 ways to Protect Your WordPress Site From Spam

Some days after you launch your website, you will notice a lot of comments from spam bots. These are very annoying and often target a certain post of the blog. The comment title consists of links and the body has some spam links and text. Spammers not only spam in comments they also steal your website content and spread it all over the web that is another reason why its important to protect wordpress from spam. There are two kinds of method used by spammers: Automated spam-bots : – Spammers use such as program and tools (robots) that can automatically submit large numbers of spam comment to numbers of blog in no time. Manual Spam : -Well in this case spammers visit your site and manually post their spam comments in the comments field. Spam Comments are a fact of life for bloggers, and no one can stop Spam Comments 100%, You can only minimize that to a lower level by using some tricks below to fight the spam on your wordpress website. 1-Install Akistmet First thing you should is ,

18 05, 2012

Ways To Get First Image From Post

Sometimes you don't have a featured image with your post. In such a case you would like to have the first image of the post as thumbnail . Here is a snippet to get the first image from post content. sometimes this trick might not work, this occurs when the DOM element has a different structure. So if this doesn't work for some reason, try adding one more regex which suits your case to make it work. You can also parse the DOM to get the image source. I will cover that topic in the next post. For now, here is how you do it through regex. function catch_that_image ($post_id=0, $width=60, $height=60, $img_script='') { // you can set any params here global $wpdb; if($post_id > 0) { // select the post content from the db $sql = 'SELECT post_content FROM ' . $wpdb->posts . ' WHERE id = ' . $wpdb->escape($post_id); $row = $wpdb->get_row($sql); $the_content = $row->post_content; if(strlen($the_content)) { // use regex to find the src of the image preg_match("/<img src\=('|\")(.*)('|\") .*( |)\/>/", $the_content, $matches); if(!$matches) { preg_match("/<img class\=\".*\"

6 05, 2012

How to retrieve the WordPress Featured Image URL

Sometimes you need the source url or path to a featured image. The reason might be that you want to use it as background somewhere or use it in src of img tag. There can be several reasons why you need the url to featured image of a post or page. Here is a trick which can be used to retrieve the url and then use it as background for a div <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> <div style='background-image: url("<?php echo $featured_image_url [0]; ?> <?php endif; ?> Remember to do $featured_image_url [0] because $featured_image_url is an array and we want to access the first member of it.Isn't this a great trick?

5 05, 2012

WordPress Frontend Posting for Users – Why?

Posting from site or posting from frontend is a popular trick for wordpress based websites. A lot of blogs and websites now allow their users to post through frontend. They do not want their users to see their backend. A page is provided at frontend where users will have only specific fields to submit their posts. The blog owner wants to provide only some fields and provide them in such a way that the user finds it easy to submit posts. I personally don't like frontend posting, since i feel its unnecessary. When you have a dashboard which displays options according to user role and you can customize the post editor page to have the fields that you want, why have a frontend post submit form? . One reason why i think people would use frontend posting trick is, they want the design of post submit form to match the rest of the site layout. In case of using the dashboard, users will see the default white and blue wordpress dashboard which doesn't seem to be very attractive. I have

4 05, 2012

How to Add pagination to Post Loop.

What is pagination By default worpress shows links for next and previous posts. Older will show the ten previous posts and newer will show the next ten posts. It is desireable to add page numbers for posts, so that you know how many post pages are there and you can move to any desired page by one click. Pagination gives navigation ease plus a more professional look to your post loop. You must have seen pagination below post loop which looks like this, How to add pagination to Post loop There are two ways of adding pagination to post loops. One is through a plugin and the other is through writing some code in your wp_query. Pagination Through Plugin I have used a pagination plugin called "WP Page Numbers" . Its a nice plugin, it gives you few templates of pagination to work with. You can choose any of them to suit your theme colors. Below you can see the templates available within the plugin itself. Pagination through Code For displaying page number below a post loop, you have to

3 05, 2012

8 Great Twitter ,Facebook, Googleplus Tricks for WordPress

1- Get User's Tweets You can get user tweets if the twitter profile is a public profile. The code below gives you the feed which can be styled in any way you like. function getTweets($user) { $page= file_get_contents("http://twitter.com/{$user}"); $from = strpos($page, "<ol id="timeline" class="statuses">"); $to = strpos($page, "</ol>"); $length = $to - $from; $page =substr($page, $from, $length); echo $page; } getTweets('axactsoft'); //replace axactsoft with your twitter username 2- Disable Admin bar Here is a trick to disable the wordpress admin bar, use this code in functions.php add_filter('show_admin_bar', '__return_false'); 3- Add Google plus one button Google plus one buttons allows user to give a rating to your blog, posts or pages. It easy to display the plus one button wherever you want. Just follow the code and instructions below. <!-- Place this tag in your head or just before your close body tag --> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <!-- Place this tag where you want the +1 button to render -->   4- Get Tweet Count. Sometimes you would not like a long list of tweets

1 05, 2012

Use shortcodes in Widget

Shortcodes if used in widgets will not be replaced by the relavant code. You can make them display proper code by using this code. // display shortcode in widgets if ( !is_admin() ){ add_filter('widget_text', 'do_shortcode', 11); } More Interesting articles on this topic: Add Shortcode for WordPress(tamilcselvan.wordpress.com)

1 05, 2012

How to Enable Threaded Comments in WordPress

You can enable threaded comments for posts using a simple trick. Wordpress does not enable threaded comments by default, but you can do it using this code in functions.php function ax_threaded_comments(){ if (!is_admin()) { if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) wp_enqueue_script('comment-reply'); } } add_action('get_header', 'ax_threaded_comments'); Thanks to wpshout for this trick.

25 04, 2012

What People Search on Your blog

A wonderful trick is to find out what people look for on you blog. A good content is not one which is full of keywords, it is what users actually want. In order to promote your blog, look for the overall search trends. Find out what people are interested in these days related to your blog's topic. You can also keep an eye on what people are liking on your blog and what they are searching for. This can be done by installing a good plugin called "Search Meter". This plugin show you a search dashboard in your wp backend showing the search on site for yesterdy, today and  last week. Install this plugin and analyze the search behaviour of visitors. Get more info from Plugin's homepage.    

WhatsApp chat