Emerald

About Yumna Tatheer

I am a Computer Science graduate and a part time blogger from Lahore, Pakistan. I am a PHP programmer and a wordpress expert.

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.

In html you will call the function as

Another way of doing that is by the code provided at codex

To use this code, you just need to call the function like this

This is another very smart method of extracting the first image. I found this one the best since it directly extracts the source attribute and does not look for specific patterns in html. Use the code below in your functions.php

Now use it anywhere in […]

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

Remember to do $featured_image_url because $featured_image_url is an array and we want to access the first member of it.Isn’t this a great trick?

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 written a simple […]

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 do 3 things

add the $paged parameter to […]

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.

2- Disable Admin bar
Here is a trick to disable the wordpress admin bar, use this code in functions.php

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.

 

4- Get Tweet Count.

Sometimes you would not like a long list of tweets shown to user. You only want to show the count of twitter followers to influence them to follow you (or not follow you lol) on twitter. You can write a simple snippet or plugin for that.First create paste the the code below in your functions.php

Now to display the count anywhere use

5- Add Social media Twitter and Facebook Buttons To postsSocial Media

sharing for your posts is must these days. It makes your blog engaging, interesting and popular. People would recommend your […]

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)

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

Thanks to wpshout for this trick.

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.

 

 

How to Remove 404 Error from Google Index

We all have experienced errors like

“Sorry. 404 page not found ”

if the resource on that url has been moved.  These 404s errors will go away by themself generally after a week or so, but if your domain has too many 404 Errors floating around in the search engines a few things may happen:
1.Your site’s reputation may be hurt.
2.Your site’s rankings may suffer.
3.Your site may be penalized.
4.Your site may be banned from the index.

As you see, a 404-Error page is a killer of SEO campaigns (404-Errors should not be confused with “server not found” or similar errors, in which a connection to the destination server could not be made at all).

Somtimes if a page is not removed from following the above steps then it might not be a 404 truly. To test if a page is a true 404 use this tool

 

Here are steps that can be followed to remove 404.

Step #1: Set Up In Google Webmaster Tools

To start the process, make sure you’re site is being tracked in Google Webmaster Tools so that it can report back any potential site […]