jQuery contains() with a variable syntax

var vtxt = 'customtext';
$("p:contains('" + vtxt + "')").addClass("on");

How to get the selected value of dropdownlist using JavaScript?



<select id="v1">
<option>amit</option>
<option>work</option>
<option>desk</option>
</select>
<button>Click</button>

$(document).ready(function(){
$('button').click(function(){
var s = document.getElementById('v1');
var v1 = s.options[s.selectedIndex].value;
    alert(v1);
});
});

How to get post thumbnail in wordpress?

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
} 
?>
<?php the_content(); ?>

this is the default method to retrieve post thumbnail
<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail(array(150,150));
} 
?>
<?php the_content(); ?>
this is the method which is used to alter that thumbnail like size in array 150px & 150px

How to hide toggle div when clicking anywhere on the page?


HTML

<div id="theDiv">Some contents</div>
<div id="showDivBtn">Toggle link</div>

STYLE

<style>
#theDiv {
    width: 50px;
    height: 50px;
    background: #e9e9e9;
}
#showDivBtn {
    margin-top:100px;
    width: 100px;
    height: 50px;
    cursor: pointer;
}

</style>

SCRIPT

<script>

$('.dropdown').fadeOut();

$(document).on('click', function(e) {
    if ( $(e.target).closest('.gbtn').length ) {
        $(".dropdown").fadeIn();
    }else if ( ! $(e.target).closest('.dropdown').length ) {
        $('.dropdown').fadeOut();
    }
});

</script>

How to add css for custom pages

<?php if ( is_page(array('somepage1', 'somepage2', 'somepage3'))) {
echo ' class="myclass" '; } ?>


or



<?php 
if ( is_page (blog)){ 
?>

<style>
.wrapper
{
background:black !important;
}
</style>

<?php
}
?>

This is custom css for blog page only.