Customize meta description in wordpress theme

wordpress tutorial for, Customize meta description in wordpress theme. In article we will tell you trick to fetch traffic using Meta tags in wordpres theme.

Customize meta description in wordpress theme

Customize meta description in wordpress theme
Customize meta description in wordpress theme

we can do using the META description tag.  We can actually control what gets displayed in our little spot.
gaining the tremendous opportunity to convert that space into traffic with wordpress websites.

Search Engines, like Google, tend to display search results in a very standard format.  Usually the TITLE of the post or page is the link that actually takes you to the post, and under that link is a description of the site linked to.

Normally we write the Meta tags in wordpress theme as follows:


<meta name="description" content="Your site Description goes here" />

Instead of this use following code in your wordpress theme.


<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php the_excerpt_rss(); ?>" />
<?php endwhile; endif; else : ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>

With adding this lines of code in your header.php file. you will be done.

set max image size in wordpress post for showing

wordpress tutorial, Here in this article, How to  set max image size in wordpress post for showing. We given simple CSS code which can be used in your style.css file.

Simply paste the following in your style.css file. This code will work with latest wordpress versions.

 set max image size in wordpress post for showing

.postarea img {
max-width: 500px;
height: auto;
}

.post img {
max-width: 500px; /* Adjust this value according to your content area size*/
height: auto;
}

.size-full {
max-width: 500px;
height: auto;
}

 set max image size in wordpress post for showing
set max image size in wordpress post for showing

add common content after every wordpress post

WordPress tutorial, In this article we will show, how to add common content after every wordpress post. We given simple code for adding in wordpress theme.

Just copy paste the following code in your functions.php file.  You will find this file in your wordpress theme folder.

add common content after every wordpress post


function insert_common_content($_common_content) {
if(!is_feed() && !is_home()) {
$_common_content.= "<div class='wordpressapi'>";
$_common_content.= "<h4>Enjoyed this article?</h4>";
$_common_content.= "Check more articles on <a href='http://images.purabtech.in/'>purabtech.in/files/</a>";
$_common_content.= "</div>";
}
return $_common_content;
}
add_filter ('the_content', 'insert_common_content');

add common content after every wordpress post
add common content after every wordpress post

Useful article related to this wordpress hack.

http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

wordpress check if post has image attachment

In custom theme checking post image is really useful because old post has no featured image set. Using our code wordpress check if post has image attachment. Just use following code the check for image in wordpress post.

wordpress check if post has image attachment

Copy paste the following function in functions.php file.


function check_image(){
$content = $post->post_content;
$all_images = '~<img [^>]* />~';

preg_match_all( $all_images, $content, $pics );

// Check to see if we have at least 1 image
$all_pics = count($pics[0]);

if ( $all_pics > 0 ) {
// Your post have one or more images.
return true
} else {
return false;

}

wordpress check if post has image attachment
wordpress check if post has image attachment

In post loop just add or call this function. This function will return the true or false.

Put Google Analytics code into your wordpress theme

Adding Google Analytics is important for website. Here in this article we given code snippet and show to Put Google Analytics code into your wordpress theme

Put Google Analytics code into your wordpress theme

Copy paste following lines to your wordpress theme folder’s functions.php file.


function google_analytics() {

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12453889-1");
pageTracker._trackPageview();
} catch(err) {}</script>
}
add_action('wp_footer', 'google_analytics');

Dont forget to replace your google analytics code in google_analytics code.

Put Google Analytics code into your wordpress theme
Put Google Analytics code into your wordpress theme

have fun!

how to add favicon to wordpress theme

Favion is small image icon which is shown on browser left top side. Left side of browser address bar, we can see the favicon image. Here in this article We will show you, how to add add favicon to wordpress theme.

how to add favicon to wordpress theme

Create favicon image using photoshop or any photo editing tool. Favicon image side should be 16x16px or 32x32px. Many times favicon image should be .ico or png format. All latest browser are able to show png format image but in old browser icon format image should be supported.

Just copy paste the following lines to your function.php file.

<?php 
function add_favicon() {
?>
<link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/favicon.ico" >
<?php 
}
add_action('wp_head', 'add_favicon');
?>

if wp_head() function added in your header.php file, If that function not added then this hack will never work

Or you can just add favicon image file in themes folder and use following code in header.php file.


<link rel="icon" href="https://purabtech.in/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="https://purabtech.in/favicon.ico" type="image/x-icon" />

how to add favicon to wordpress theme
how to add favicon to wordpress theme

How to add social media buttons to wordpress sidebar

First you need to download social icons. Make sure icons are free. add social media buttons to wordpress sidebar Using simple HTML code, given by us. You just need copy and paste following code in to your sidebar text wordpress widget.

How to add social media buttons to wordpress sidebar

I created following steps to add the icons to wordpress site for non developers.

1. Upload the icon image(s) to your media library.

How to add social media buttons to wordpress sidebar
How to add social media buttons to wordpress sidebar

2. Add a “Text” widget to your sidebar and insert code similar to the following:


<a href="http://twitter.com/wordpressapi"><img src="http://images.purabtech.in/twitter_48x48.png" alt="" /></a><a href="facebook.com/wordpressapi"><img src="http://images.purabtech.in/facebook_48x48.png" alt="" /> </a>
<a href="mailto:support@purabtech.in/files/"><img src="http://www.wordpress.com/wp-content/uploads/email_48x48.png" /></a> 
<a href="http://images.purabtech.in/feed/"><img src="http://images.purabtech.in/rss_48x48.png" /></a> 
 

Then just change the URLs so that they point to your icons and links. As you can see,

I have four icons in my sidebar (twitter, facebook, email, and rss).

How to exclude images from wordpress post

In one of our project, we got the requirement of exclude images from wordpress post while showing post. We have written code for excluding the image from Post.

How to exclude images from wordpress post

you can use following code in functions.php file or you can use in single.php file. These files you can find in wordpress theme folder.

For changing the code you can use the wordpress admin -> editor section.

Above line I added in showing post without image.


<?php
$FormatedContent = content_with_formatting();
$content = the_content();
$postWithoutImage = preg_replace('/<img[^>]+./’,'' $FormatedContent);
echo $postWithoutImage;
?>

In above code we are checking the image tag and replacing with none.

If you want to find all images from post then Use following command.

preg_match_all('/<img[^>]+>/i',YOUR_text, $result);

You need to add following function in your function.php file(Theme files).

function content_with_formatting($more_link_text = ‘(more…)’, $stripteaser = 0, $more_file = ”)
{
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]>’, $content);
return $content;
}

If you want to Hide all images using CSS then use following code

img{
display:none;
}

Just put above code in your style.css file.

Fetch the wordpress post paragraph number wise

In this article we given code for Fetch the wordpress post paragraph number wise. created One function for fetching the wordpress post as per p tag number.

Fetch the wordpress post paragraph number wise

# You can Use this function for showing

function paragraph_show($paragraph_number, $post_content){
$show_after_paragraph_tag = 1;
$paragraph_number= $paragraph_number - 1;
//echo $paragraph_number;
$content = apply_filters('the_content', $post_content);

if(substr_count($content, '

') > $show_after_paragraph_tag)
//echo substr_count($content, '

');

{
$contents = explode("

", $content);
$p_count = 0;
foreach($contents as $content)
{
//echo $p_count;
if($paragraph_number == $p_count){
echo $content;
}

$p_count++;
}
}
}

We can use this function like this.

In while loop you can use or paste following code

#This will show the first paragraph of post.
post_content);

How to use Custom Page as Homepage in WordPress

wordpress tutorial, How to use Custom Page as Homepage in WordPress. Here we given full step by step explanation about using custom template.

This is one of the most wanted hacks that users want to know how to accomplish. First you need to learn how to create a custom page. You will need to duplicate your page.php or create a wordpress.php file and add the following code at the very top:

How to use Custom Page as Homepage in WordPress

wordpressapi */ ?>

How to use Custom Page as Homepage in WordPress
How to use Custom Page as Homepage in WordPress

You can change the template name. Change any styling, that you want in that page. Go to your WordPress admin panel and create a new page and select this template(wordpressapi).

custompagetemplate

Select your page to be the homepage as per your choice. Now you have yourself a Custom Home Page.

Have fun!