Tuesday, 25 February 2014

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>

Saturday, 8 February 2014

Show related posts without a plugin

Installing the code below will make your WordPress site display related posts based on the current post tag(s). You need to place it inside single.php, or simply anywhere you want to show the related posts.

<?php 
    $tags = wp_get_post_tags($post->ID); 
    if ($tags) { 
        $tag_ids = array(); 
        foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; 
        $args=array( 
        'tag__in' => $tag_ids, 
        'post__not_in' => array($post->ID), 
        'showposts'=>5, // Number of related posts that will be shown. 
        'caller_get_posts'=>1 
        ); 
    $my_query = new wp_query($args); 
        if( $my_query->have_posts() ) { 
            echo '<h3>Related Posts</h3><ul>'; 
            while ($my_query->have_posts()) { 
                $my_query->the_post(); 
                ?> 
                <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> 
            <?php 
            } 
            echo '</ul>'; 
        } 
    } 
?> 

Friday, 31 January 2014

Uploading Image ffiles Default wordpress upload


     <?php
    require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');

?>
<input type="file" name="file-upload" id="file-upload" /><select name="post_id" required="true">
 
/*************************************************************************/       
        if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/default/file.php' );
$uploadedfile = $_FILES['file'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
    echo '<div id="msg">'.'File is valid, and was successfully uploaded'.'</div>';
    var_dump( $movefile);
   
} else {
    echo '<div id="msg">'.'Possible file upload attack!'.'</div>';
}
/********************************************************************/

Saturday, 25 January 2014

Add text box dynamicaly in javascript

Custom html and javascript cde 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$('document').ready(function() {
    //alert('ffdfd');
$("#txt1").keydown(function(e) {
    var order = e.which;
    //alert(order);
    if ( e.which === 13 ) {
        // Disable line break
        textChange(order);
        e.preventDefault();

        // Do things

    }
});
});
    function textChange(event1){
        var event=event1;
    // Get the number of the caller's id
    var i=0;
   
    alert(i);
   
    $("#me").append("<input type='text' id='txt1'/>");
    }
</script>
<from id="me" name="me" >
    <input type="text" id="txt1"/><input type="submit" value="submit">
</form>

code for wordpress
<script type="text/javascript">
    $(document).ready(function($)
    {
   
$("#logo").keydown(function(e) {
    var order = e.which;
    //alert(order);
    //textChange(order);
    if ( e.which === 13 ) {
        // Disable line break
        textChange(order);
        e.preventDefault();

        // Do things

    }
});
 function textChange(event1){
    var i;
    i=i+1;
    //$("#insertnew").html("<input type='text' id='"+i+"'value='know my value'/>");
   
   
    $("#insertnew").append("<br><input type='text' id='ss"+i+++"'value='know my value'/>");
    i++;

}
   
    });
</script>