Friday, 28 February 2014

SEO Friendly URL Structure for WordPress

WordPress URL Structure by default is not the most Search Engine Friendly, and it is also not very user friendly. In this tutorial we will show you how to make SEO Friendly URL Structure for WordPress that are also user friendly. If you see us use Permalink structure instead of URL structure, you should know that they are synonymous.

Why SEO Friendly URL Structure

When you have a SEO friendly structure, you are increasing your chances of ranking higher in search engines such as Google and others. Which by default are the largest source of new visitors to any website. In our experience with SEO, we have seen that Google gives extra weight to the URL structure therefore it is recommended that you follow this tutorial.

Begin Process

By default WordPress URL Structure looks a bit more robotic because it is not user friendly at all let alone not being SEO friendly.
http://wpbeginner.com/?p=25

Above is an example of what a default WordPress URL structure looks like. The goal of making the URL structure more friendly is that your users should know before reading the article what it is about by just looking at the URL. The same goal is to be accomplished for Search Engines as well.

Step 1: Open the Permalink Option Page


First you need to open the Permalink Option Page which you can find in your WordPress Admin Panel if you click on the Setting Tabs and then go to Permalink. There you should see something which looks familiar to the image above.
You would need to click on the fifth option which says Custom Structure.

Step 2: Pick Your Structure from Documentation

There are many ways a URL can be organized. WordPress gives a few options which you can see at two, three, and four. But those are not the best option in our opinion.
We recommend the URL Structure of
/%category%/%postname%/
or if someone wants a completely static site, then they can use the version below.
/%category%/%postname%.html
By using that documentation your URL structure will be keyword rich as it will contain the keyword of the category and the title. Like the one below:
http://www.wpbeginner.com/wp-tutorials/how-to-install-WordPress-on-your-site/
Now while we recommend the options above there are multiple other ways you can organize your URLs. We have seen many different options in use. To know the possible URL Structure combination, you will need to learn a few documentation tags.
%year% – The year of the post, four digits, for example 2004
%monthnum% – Month of the year, for example 05
%day% – Day of the month, for example 28
%hour% – Hour of the day, for example 15
%minute% – Minute of the hour, for example 43
%second% – Second of the minute, for example 33
%postname% – A sanitized version of the title of the post (post slug field on Edit Post/Page panel). So This Is A Great Post! becomes this-is-a-great-post in the URL.
%post_id% – The unique ID # of the post, for example 423
%category% – A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI.
%author% – A sanitized version of the author name.
More information about the tags can be found in WordPress Codex for Permalinks.
Once you have selected the combination, paste it in the field and click “Save Changes”
Your .htaccess file will automatically be updated, and your URL will be changed. We suggest that you do this towards the start of your website, so you don’t have to go through the process of re-indexing in search engine.
Good Luck with Ranking High in Search Engines.

Thursday, 27 February 2014

Introduction to Sass for New WordPress Theme



As a new WordPress theme designer, you would quickly learn the challenges of maintaining long CSS files while keeping them organized, scalable, and readable. You will also learn that many designers and front-end developers recommend using a CSS preprocessor language like Sass or LESS. But what are these things? and how do you get started with them? This article is an introduction to Sass for new WordPress Theme Designers. We will tell you what a CSS preprocessor is, why you need it, and how to install and start using them right away.

What is Sass?

The CSS that we use was designed to be an easy to use stylesheet language. However web has evolved, and so is the need of designers to have a stylesheet language that allows them to do more with less effort and time. CSS preprocessor languages, like Sass, allow you to use features that are not currently available in the CSS such as using variables, basic math operators, nesting, mixins, etc.

Getting Started With Sass for WordPress Theme Development

Most theme designers use local development environment to work on their themes before deploying it to a staging environment or a live server. Since Sass is a preprocessor language, you will need to install it on your local development environment.
First thing you need to do is to install Sass. It can be used as a command line tool, but there are also some nice GUI Apps available for Sass. We recommend usingKoala, which is a free opensource app available for Mac, Windows, and Linux.
For the sake of this article, you will need to create a blank theme. Simply create a new folder in /wp-content/themes/. You can name it ‘mytheme’ or anything else you want. Inside your blank theme folder create another folder and name it stylesheets.
In the stylesheets folder, you need to create a style.scss file using a text editor like Notepad.
Now you need to open Koala and click on the plus icon to add a new project. Next, locate your theme directory and add it as your project. You will notice that Koala will automatically find the Sass file in your stylesheets directory and display it.
Right click on your Sass file and select Set Output Path option. Now select the root of your theme directory, example, /wp-content/themes/mytheme/ and hit enter. Koala will now generate CSS output file in your theme directory. To test this you need to open your Sass file style.scss in a text editor like Notepad and add this code:
What about CSS @import?
The problem with using @import in your CSS file is that each time you add an @import, your CSS file makes another HTTP request to the server. This effects your page load time which is not good for your project. On the other hand, when you use @import in Sass, it will include the files in your Sass file and serve them all in a single CSS file for the browsers.
To learn how to use @import in Sass, first you need to create a reset.scss file in your theme’s stylesheets directory and paste this code in it.


As a new WordPress theme designer, you would quickly learn the challenges of maintaining long CSS files while keeping them organized, scalable, and readable. You will also learn that many designers and front-end developers recommend using a CSS preprocessor language like Sass or LESS. But what are these things? and how do you get started with them? This article is an introduction to Sass for new WordPress Theme Designers. We will tell you what a CSS preprocessor is, why you need it, and how to install and start using them right away.

What is Sass?

The CSS that we use was designed to be an easy to use stylesheet language. However web has evolved, and so is the need of designers to have a stylesheet language that allows them to do more with less effort and time. CSS preprocessor languages, like Sass, allow you to use features that are not currently available in the CSS such as using variables, basic math operators, nesting, mixins, etc.

Getting Started With Sass for WordPress Theme Development

Most theme designers use local development environment to work on their themes before deploying it to a staging environment or a live server. Since Sass is a preprocessor language, you will need to install it on your local development environment.
First thing you need to do is to install Sass. It can be used as a command line tool, but there are also some nice GUI Apps available for Sass. We recommend usingKoala, which is a free opensource app available for Mac, Windows, and Linux.
For the sake of this article, you will need to create a blank theme. Simply create a new folder in /wp-content/themes/. You can name it ‘mytheme’ or anything else you want. Inside your blank theme folder create another folder and name it stylesheets.
In the stylesheets folder, you need to create a style.scss file using a text editor like Notepad.
Now you need to open Koala and click on the plus icon to add a new project. Next, locate your theme directory and add it as your project. You will notice that Koala will automatically find the Sass file in your stylesheets directory and display it.
Right click on your Sass file and select Set Output Path option. Now select the root of your theme directory, example, /wp-content/themes/mytheme/ and hit enter. Koala will now generate CSS output file in your theme directory. To test this you need to open your Sass file style.scss in a text editor like Notepad and add this code:
What about CSS @import?
The problem with using @import in your CSS file is that each time you add an @import, your CSS file makes another HTTP request to the server. This effects your page load time which is not good for your project. On the other hand, when you use @import in Sass, it will include the files in your Sass file and serve them all in a single CSS file for the browsers.
To learn how to use @import in Sass, first you need to create a reset.scss file in your theme’s stylesheets directory and paste this code in it.

Tuesday, 25 February 2014

Adding Share Buttons as Overlay for YouTube Video Playlists in WordPress

After publishing this article many of our readers asked, how this code can be modified to work for YouTube playlists as well as videos. If you embed YouTube videos as well as playlists on your WordPress site, then you should use this code instead.
/*
* WPBeginner's Share Overlay Buttons
* on YouTube Videos and Playlists
*/

function wpb_yt_buttons($atts) { 

// Get the video and playlist ids from shortcode

extract( shortcode_atts( array(
 'video' => '',
 'playlist' => '',
  ), $atts ) );
   
// Check to see if a playlist id is provided with shortcode   
   
 if (!$playlist == '' ) : 

// Display video playlist
  
 $string = '<div id="video-container"><iframe src="//www.youtube.com/embed/' . $video . '?list=' . $playlist . '" height="315" width="560" allowfullscreen="" frameborder="0"></iframe>';

// Add Facebook button  
 $string .= '<ul class="share-video-overlay" id="share-video-overlay"><li class="facebook" id="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fyoutube.com/watch%3Fv%3D'. $video . '%26list%3D' . $playlist . '" target="_blank">Facebook</a></li>'; 

// Add Twitter button 
 $string .= '<li class="twitter" id="twitter"><a href="http://www.twitter.com/share?&text=Check+this+video&amp;url=http%3A//www.youtube.com/watch%3Fv%3D'. $video . '%26list%3D' . $playlist . '">Tweet</a></li></ul>';

// Close video container    
 $string .= '</div>';
  
// If no playlist ID is provided 
 else : 

//Display video  
 $string .= '<div id="video-container"><iframe src="//www.youtube.com/embed/' . $video . '" height="315" width="560" allowfullscreen="" frameborder="0"></iframe>';

// Add Facebook button  
 $string .= '<ul class="share-video-overlay" id="share-video-overlay"><li class="facebook" id="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fyoutube.com/watch%3Fv%3D'. $video .'" target="_blank">
 Facebook</a></li>';
 
// Add Twitter button   
 $string .= '<li class="twitter" id="twitter"><a href="http://www.twitter.com/share?&text=Check+this+video&amp;url=http%3A//www.youtube.com/watch%3Fv%3D'. $video .'">Tweet</a></li></ul>';

 // Close video container   
  $string .= '</div>';
  
 endif;
  
// Return output  
 return $string; 
} 

// Add shortcode
add_shortcode('wpb-yt', 'wpb_yt_buttons');
 
Using the code above you can also add a playlist with overlaying share buttons. To display your playlist you will have to provide the video id and playlist id in the shortcode like this:
[wpb-yt video="exP9N3rIfV0" playlist="UUhA624rCabHAmd6lpkLOw7A"]
 

Add Share Buttons as Overlay on YouTube Videos in video gallary WordPress

Videos are one of the best ways to boost user engagement. Recently one of our users asked us about a way to create share button overlays on videos similar to the popular site UpWorthy. In this article, we will show you how to add share buttons as overlay on YouTube videos in WordPress.
There were several ways that this could be done. Most ways would require you to paste a bits of HTML code every time you add a video. Instead of doing that, we decided to create a shortcode that would automate this overlay effect.
Simply copy and paste the following code in a site-specific plugin or your theme’sfunctions.php file:
/// WPBeginner's YouTube Share Overlay Buttons

function wpb_yt_buttons($atts) { 

// Get the video ID from shortcode
extract( shortcode_atts( array(
 'video' => ''
 ), $atts ) );

// Display video
 
$string = '<div id="video-container"><iframe src="//www.youtube.com/embed/' . $video . '" height="315" width="560" allowfullscreen="" frameborder="0"></iframe>';

// Add Facebook share button
 
$string .= '<ul class="share-video-overlay" id="share-video-overlay"><li class="facebook" id="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fyoutube.com/watch%3Fv%3D'. $video .'" target="_blank">
 Facebook</a></li>'; 

// Add Tweet button 
$string .= '<li class="twitter" id="twitter"><a href="http://www.twitter.com/share?&text=Check+this+video&amp;url=http%3A//www.youtube.com/watch%3Fv%3D'. $video .'">Tweet</a></li></ul>';

// Close video container    
 $string .= '</div>';

// Return output 
 return $string; 

} 
// Add Shortcode 
add_shortcode('wpb-yt', 'wpb_yt_buttons');
 
This code creates a shortcode that automatically adds twitter and facebook share links to your videos. These buttons are only visible when the user brings their mouse over the video. You can use it add any other social media channel as well.
To use this shortcode, all you will need to do is add the YouTube video ID in the shortcode like this:
[wpb-yt video="qzOOy1tWBCg"]

Thursday, 20 February 2014

How to Fix Featured Images Appearing Twice in WordPress Posts

The WordPress users, creating a post in WordPress is  easy process. However for those just starting out, there are still things that they might find confusing. While the featured images functionality is a total life saver, it requires some basic understanding of WordPress to properly use it. Recently one of our readers reached out to us with a problem that their featured image was displaying twice. It is a fairly common image problem that can easily be solved. In this article, we will show you how to fix featured images appearing twice in WordPress posts.
Featured Image or Post Thumbnail appearing twice in WordPress posts

Why Featured Image is appearing Twice in my WordPress Posts?

The most common reason for a featured image or post thumbnail to appear twice in WordPress posts is that sometimes beginners set a featured image and also insert it into the post content.
This actually makes sense to most beginners because when they set a featured image, they expect it to appear in their visual post editor. When it does not appear in the visual post editor, they feel that they may have missed something and end up inserting the same image again in the post. This time they can see it in the visual post editor and feel satisfied. But when they publish the post, they notice that the image is appearing twice on their post.
How to Fix this?
Just remove the image from the post editor and make sure you use the featured image box to set your featured image.
Avoiding duplicate images when setting featured image in WordPress
Featured images or post thumbnails are a WordPress theme feature. This means that the support for this feature is handled by your WordPress theme which is why you don’t see how it looks in your post editor.
When you set a featured image for a post, the database communicates with your theme that there is a featured image that can be displayed automatically. This allows theme developers to use consistent styles for post thumbnails and featured images through out your website.
While this may fix the duplicate featured image issue for most users, you may also come across some other surprising issues. For example if you change the theme, then your featured images may look stretched, skewed, and disproportionate. To fix this you will need to regenerate image sizes in WordPress.
If the above solution does not help fix the problem of featured images appearing twice, then there is an issue with the underlying code of your theme. In this case, the best solution is to contact your theme developer for help.
Check out the solution for other common image issues in WordPress.
We hope this article helped you fix featured images appearing twice in your WordPress posts. For questions and feedback, feel free to leave us a comment below. You can also reach out to us on Twitter and Google+.

Wednesday, 19 February 2014

onmouseover and onmouseout:

These two event types will help you to create nice effects with images or even with text as well. The onmouseover event occurs when you bring your mouse over any element and the onmouseout occurs when you take your mouse out from that element.

Example:

Following example shows how a division reacts when we bring our mouse in that division:
<html>
<head>
<script type="text/javascript">
<!--
function over() {
   alert("Mouse Over");
}
function out() {
   alert("Mouse Out");
}
//-->
</script>
</head>
<body>
<div onmouseover="over()" onmouseout="out()">
<h2> This is inside the division </h2>
</div>
</body>
</html>

What is an Event ?

JavaScript's interaction with HTML or HTML 5 is handled through events that occur when the user or browser manipulates a page.
When the page loads, that is an event. When the user clicks a button, that click, too, is an event. Another example of events are like pressing any key, closing window, resizing window etc.
Developers can use these events to execute JavaScript coded responses, which cause buttons to close windows, messages to be displayed to users, data to be validated, and virtually any other type of response imaginable to occur.
Events are a part of the Document Object Model (DOM) Level 3 and every HTML 5 element have a certain set of events which can trigger JavaScript Code.
Please go through this small tutorial for a better understanding HTML Event Reference. Here we will see few examples to understand a relation between Event and JavaScript:

onclick Event Type:

This is the most frequently used event type which occurs when a user clicks mouse left button. You can put your validation, warning etc against this event type.

<html>
<head>
<script type="text/javascript">
<!--
function sayHello() {
   alert("Hello World")
}
//-->
</script>
</head>
<body>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>