In wordpress get all tags in drop down terms

WordPress tags are very important. For SEO we use tags. Here in this article we will show post tags in drop down box using simple php script.

Little Background about creating tag drop down

For one of my wordpress plugin, I want to show tags drop down in widget setting form. I created plugin called “Smart Posts Widget“. For this wordpress plugin, I created tag drop down.

In wordpress get all tags in drop down terms
In wordpress get all tags in drop down terms

I used following code for creating drop down. If you want to create wordpress post tag drop down for some setting or configuration use following simple code.


<?php
$taxonomies=get_taxonomies('','object');
foreach($taxonomies as $tax){
echo "<h2>$tax->name</h2>";
$terms = get_terms( $tax->name, 'orderby=count&hide_empty=0' );
foreach($terms as $term){
print_a($term->name);
}
}
?>

Above is raw code, which I modified little bit to create drop down list of wordpress post tags.

get all tags in drop down terms

For tag drop down you can use following code.


<p style="display:<?php if($instance["cat_tag"]=='tag'){echo 'block';}else {echo 'none';} ?>" class="<?php echo $this->get_field_id('selected_tag'); ?>">
<label for="<?php echo $this->get_field_id('selected_tag'); ?>">
<?php _e( 'Tags' ); ?>:
<select id="<?php echo $this->get_field_id('selected_tag'); ?>" name="<?php echo $this->get_field_name('selected_tag'); ?>" >
<?php $tags = get_tags('orderby=name&order=ASC'); foreach($tags as $tag) {?>
<option value="<?php echo $tag->term_id;?>"<?php selected($instance['selected_tag'],$tag->term_id); ?> ><?php echo $tag->name; ?></option>
<?php }?>
</select>
</label>
</p>

Above Code in used in smart posts widget plugin, which is working fine with latest wordpress versions.

 

wordpress tutorial – How to create template with easy steps

Here in this article We will show, How to create template using easy steps. We written many wordpress tutorials about creating many types of custom templates. For custom pages always we need new look and feel. Some time we need separate functionality for specific pages.

Following are list of template wordpress tutorials which might be useful for you.

create author page template in wordpress theme
create links template page in wordpress theme
create contact us template page in wordpress
how to create contact us page without plugin
 

wordpress tutorial – How to create template

Creating custom page template is very easy, For creating custom template you need to create php file in your wordpress theme folder.

How to create template

You need to create new php file in wrodpress theme folder. Go to your theme’s folder (wp-content/themes/your-theme).

Create a New PHP File

Always create custom template with extension -page.php . Here I am giving example of creating contact us page. So we will create page called “contact-us-page.php”.

Add Following Code

Use following code and just copy paste following code in contact-us-page.php file

<?php
/*
Template Name: Contact Us
*/

 

Select Template from drop-Down menu

So, your Custom Page Template is now built, but you will still need to choose it whenever you want to use it. You do that by going to the right-hand side of the screen whenever you’re writing a Page. You should see a section there that says, “Templates” with a pull-down menu.

how to create contact us page without wordpress plugin
how to create contact us page without wordpress plugin

If you need full code of contact us page than check following URL:

create contact us template page in wordpress

Using above easy code you can create custom page template in any wordpress theme. You can create custom styling for template page which will be applicable for only selected pages.

automatically delete spam comments in wordpress

WordPress Spam comments is big issue. I am getting daily 5k spam comments daily. we automated task of  deleting spam comments automatically. Daily going to comments dashboard and deleting spam comments is really boring task. WordPress Akismat wordpress plugin does good job of finding spam comments.

automatically delete spam comments in wordpress
automatically delete spam comments in wordpress

 

How to automatically delete spam comments in wordpress?

I am using Akismat wordpress plugin for my all wordpress blogs. It does good job of finding spam comments. Due to spam comments. comment-meta table becoming big and causing mysql resource issues. So cleaning comments table became necessary. so we used following hook in wordpress theme code.


function auto_delete_spam_comments() {
$in_progress = (bool) get_site_option( 'spamcomment_delete_in_progress' );
if ( ! $in_progress ) {
global $wpdb;
update_site_option( 'spamcomment_delete_in_progress', '1' );
// 4980
$next = (int) get_site_option( 'spamcomments_delete_next_blog' );
if ( empty( $next ) ) {
$next = 1;
}

if ( $next > 3000 ) {
return;
}
switch_to_blog( $next );

$spams = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->comments} WHERE comment_approved = 'spam' LIMIT 10" );
if ( empty( $spams ) ) {
$next++;
update_site_option( 'spamcomments_delete_next_blog', $next );
} else {
foreach ( $spams as $spam ) {
wp_delete_comment( $spam, true );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id = %d", $spam ) );
}
}
// reclaim disk space
$wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" );
$wpdb->query( "OPTIMIZE TABLE {$wpdb->commentmeta}" );
restore_current_blog();
delete_site_option( 'spamcomment_delete_in_progress' );
}
}
register_shutdown_function( 'auto_delete_spam_comments' );

Notes:
The number of blogs is hardcoded (3000)
Add above code in functions.php file.

If you want WordPress to automatically empty my spam comments after 1 day. Just add this to wp-config.php. Following code will automatically Empty Your WordPress Trash

/**
 * Delete Spam Comments.
 */
define( 'EMPTY_TRASH_DAYS', 1 );

To disable trash set the number of days to zero. Note that WordPress will not ask for confirmation when someone clicks on “Delete Permanently”.

define( 'EMPTY_TRASH_DAYS', 0 ); // Zero days

If you want more information Automatically empty wordpress Trash comments and posts and How to make empty wordpress trash automatically

create author page template in wordpress theme

We have many guest authors who writes in our blogs. So creating author page is good idea. Here in this article we created author page template in wordpress theme. There are many wordpress plugins available which will give you facility to show author list.

Without wordpress plugin show author list

Here we created simple wordpress page template for showing author list in wordpress website. we created authorlist.php file in wordpress theme folder and added following code in that file.


<?php
/*
Template Name: AuthorList
*/

get_header(); ?>

&nbsp;&nbsp; &nbsp;<div id="primary" class="content-area clr">
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<div id="content" class="site-content left-content" role="main">
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<div id="authorlist"><ul><?php contributors(); ?></ul></div>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</div><!-- #content -->
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<?php get_sidebar(); ?>
&nbsp;&nbsp; &nbsp;</div><!-- #primary -->
<?php get_footer(); ?>

 

Open your functions.php file and put following contributors function in that file.

 


function contributors() {
global $wpdb;

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY user_registered");

foreach ($authors as $author) {

echo "<li>";
echo "<a href=\"" . get_bloginfo('url') . "/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
echo get_avatar($author->ID);
echo "</a>";
echo '<div>';
echo "<a href=\"" . get_bloginfo('url') . "/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
the_author_meta('display_name', $author->ID);
echo "</a>";
echo "<br />";
echo "Website: <a href=\"";
the_author_meta('user_url', $author->ID);
echo "/\" target='_blank'>";
the_author_meta('user_url', $author->ID);
echo "</a>";
echo "<br />";
echo "Twitter: <a href=\"http://twitter.com/";
the_author_meta('twitter', $author->ID);
echo "\" target='_blank'>";
the_author_meta('twitter', $author->ID);
echo "</a>";
echo "<br />";
echo '<div >';
the_author_meta('description', $author->ID);
echo '</div>';

echo "<br />";
echo "<a href=\"" . get_bloginfo('url') . "/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">Visit&nbsp;";
the_author_meta('display_name', $author->ID);
echo "'s Profile Page";
echo "</a>";
echo "</div>";
echo "</li>";
}
}

add above code in functions.php file. You can change styling as per your website code.

 create author page template in wordpress theme

Now login to wordpress admin panel and go to pages. Create new page called “Author List”. From Page Attributes section you need to select Template.

create author page template in wordpress theme
create author page template in wordpress theme

 

As per shown in above Image. You need select “AuthorList” in Template DropDown and save the page. Than add Authorlist page add in menu. Now you are able to see the Authorlist without extra wordpress plugin.

If you want to add JavaScript and CSS in page template page than refer our article. You can create contact us page template using similar type of code.

 

add nofollow and _blank target to wordpress author bio

wordpress seo tips, Here in this article, we shown how to add nofollow and _blank target to wordpress author bio (Biographical Info) section. I am writing blog since 2008. I written on many topics and many blogs. I always accept article from guest author. Some of guest author want to publish their company or personal information in author bio section.

Some months before google changed search engine algorithm. Google look in blog, how many direct out links are used in site. I have many author articles and bio section published in our blogs. We decided to add Nofollow and new tab link attribute in for author bio section.

add nofollow and _blank target to wordpress author bio

If you manually try to add blank target and nofollow for anchor tag. wordpress removes nofollow and target from author bio section using hook.

add nofollow and _blank target to wordpress author bio
add nofollow and _blank target to wordpress author bio

We used simple str_replace method to modify the author bio section.

We created post-author.php file and added following code in that file.

if ( ! function_exists( 'wpapi_post_author' ) ) {

function wpapi_post_author() {

// Only display for standard posts
global $post;
$post_id = $post->ID;
if ( 'post' !== get_post_type($post_id) ) return;

// Vars
$author = get_the_author();
$author_description = get_the_author_meta( 'description' );
$author_description = str_replace('href','rel="nofollow" target="_blank" href', $author_description);
$author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
$author_avatar = get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'wpapi_author_bio_avatar_size', 75 ) );

// Only display if author has a description
if ( !$author_description ) return; ?>

<div class="author-info boxed clr">
<h4 class="heading"><span><?php printf( __( 'Written by %s', 'wpapi' ), $author ); ?></span></h4>
<div class="author-info-inner clr">
<?php if ( $author_avatar ) { ?>
<a href="<?php echo $author_url; ?>" rel="author" class="author-avatar">
<?php echo $author_avatar; ?>
</a>
<?php } ?>
<div class="author-description">
<p><?php echo $author_description; ?></p>
</div><!-- .author-description -->
</div><!-- .author-info-inner -->
</div><!-- .author-info -->

<?php } // End function

} // End if

After this we added following line in functions.php file


// Outputs post author bio
require( get_template_directory() .'/functions/post-author.php' );

If you dont want to create separate file than you can directly add above code in functions.php file.

Above code replace all herf with rel=”nofollow” target=”_blank” href tag. When we add any link in author bio section that will replaced.

This really useful for wordpress website SEO because google will trust URLs in author section.

Change ‘Enter Title Here’ Text for custom wordpress post

WordPress has functionality of create custom post type. By default wordpress shows “Enter Title Here” for every post type. Basically every content type is custom post in wordpress. When you create new post you will able to see this placeholder text.

For custom post type we need to add  Change ‘Enter Title Here’ Text for custom wordpress post. Many times we create custom post type for custom projects. Here in this article we shown you, how to create custom post type and change placeholder text.

When we want to customize custom post

If we are creating product custom type and want to add product description and their photos. For that you cannot use ‘Enter Title Here’ text. You need to give information to admin users with clear directions. So many times with custom post type you need to change placeholder text.

Using Following code You can create custom Post type

You need open functions.php file from your theme files and put following code.


add_action( 'init', 'create_product_init' );
/**
* Register a product post type.
*
* @link https://purabtech.in/create-wordpress-custom-post-type-permalink-structure/
*/
function create_product_init() {
$labels = array(
'name'               =>'Products',
'add_new_item'       => __( 'Add New product', 'your-plugin-textdomain' ),
'new_item'           => __( 'New product', 'your-plugin-textdomain' ),
'edit_item'          => __( 'Edit product', 'your-plugin-textdomain' ),
'view_item'          => __( 'View product', 'your-plugin-textdomain' )

);

$args = array(
'labels'             => $labels,
'public'             => true,
'publicly_queryable' => true,
'show_ui'            => true,
'show_in_menu'       => true,
'query_var'          => true,
'rewrite'            => array( 'slug' => 'product' ),
'capability_type'    => 'post',
'has_archive'        => true,
'hierarchical'       => false,
'menu_position'      => null,
'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);

register_post_type( 'product', $args );
}

 

Using above code you can create Product custom post.

Now Change ‘Enter Title Here’ Text for custom wordpress post

Use following code in functions.php file.


add_filter( 'enter_title_here', 'custom_product_enter_title' );

function custom_product_enter_title( $input ) {
global $post_type;

if ( is_admin() && $post_type == 'product')
return __( 'Enter Product Name here', 'your_textdomain' );

return $input;
}

 

Change ‘Enter Title Here’ Text for custom wordpress post
Change ‘Enter Title Here’ Text for custom wordpress post

 

Changed Placeholder text will look like as above shown in image. It is very simple and short code. You can change above code as per your project requirement.

For displaying custom post type on wordpress page you can check this article. If you want to upload file with meta box in wordpress with custom post type than check this article. There are many wordpress tutorial we written about wordpress custom post type.

 

wordpress get random posts from category

In wordpress widget or on homepage, In wordpress get random posts from category. Here in wordpress tutorial we have given some nice tricks and tips for wordpress developers. There are many ways to achieve this. I can recommend to use Page Builder Plugin and use smart posts widget plugin.

wordpress get random posts from category

Above plugin will not add any database table to your wordpress website. We prefer to use the above plugin. Using smart posts widget plugin, you can show random post with simple setting or configuration.

Still you want to show random post by using code than use following code.

 

$query_params="post_type=post&showposts=10&cat=12&orderby=rand&order=DESC";
$smart_posts = new WP_Query($query_params);

while ( $smart_posts->have_posts() )
{
$smart_posts->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<?php the_post_thumbnail(); ?>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</a>
<?php the_excerpt(); ?> 

<?
}
wp_reset_postdata();


 

 

Features of Plugin which shows every types of posts.

Smart Posts Widget

wordpress get random posts from category
wordpress get random posts from category

 

Smart Posts Widget – is designed to show your posts as you want without any programming knowledge. display all type of post types from a certain post type or post category or post tags.

There are many options for user to filter or order posts. You can able to select many options to choose your posts.

Smart Posts Widgets developed to provide very easy to user for displaying all types of posts within your widget areas.

widget is compatible with Page Builder. You can create beautiful page layouts and show posts as per your choice.

Google, Bing Verify ownership with wordpress website

Webmaster verification is process which will enables some site management tools by provided by google, Bing and Yandex. Here we given full steps for Google, Bing Verify ownership with wordpress website.

Why website verification is important?

Site Verification will not increase your page rank or search results of your website, It will help you to optimize your website with SEO tools.

Verify your website

If you have custom sitemap XML then you should open webmaster account and tell search engine about your sitemap file. If you have sitemap.xml file in webroot still we recommend to submit your sitemap file to search engine.

Google, Bing Verify ownership with wordpress Website

Manual Process for Verify ownership with wordpress website

Google

  1. Login to your Google Webmaster Account (if your website has Google Analytics, Google Adsense or Google Search, you can use the same Google account). If you don’t have one, you can create one for free on www.google.com/accounts.
  2. On Google Webmaster Tools click ‘Verify this site’.
  3. In the Verification method list, select ‘Meta tag’ and copy the part of the Meta tag code provided by Google that is inside content=”…”.

Google+ (the social network)

  1. Make sure you have a link from your Google+ Page to your website. Easiest place to do this is in the “Recommended Links” section of your Google+ Page’s “About” tab.
  2. Paste your Goggle+ Page ID number, which is part of the URL for your Page. For example, the URL for YWDs’s Page is https://plus.google.com/u/0/purabkharat/posts so our ID number is purabkharat.

Bing

  1. Create a Bing Webmaster Tool account (Windows Live ID required) or login if you already have one.
  2. Add your website
  3. In ‘Option 2 (Meta Tag Authentication)’ select copy the part of the Meta tag code provided by Bing that is inside content=”…”.

Pinterest

  1. Go to your Pinterest page select “Settings”.
  2. Scroll down to “Website”. Enter your website URL iinto the filed. Click the “Verify Website” button.
  3. Click the link “Verify with a meta tag”. Copy the part of the Meta tag code provided by Pinterest that is inside content=”…”.

Automated Process for Verify ownership with wordpress website

Seo Meta Tags (https://wordpress.org/plugins/seo-meta-tags/)

This wordpress plugin gives facility to add Google, Bing Verify ownership with wordpress using WebMaster tool and meta tag added Social AuthorShip meta Tags added for Facebook, Twitter. You do not need to install too many plugin for wordpress SEO. You can just install SEO Meta tags plugin. It will handle all SEO aspects of your wordpress website.

Google Bing Verify ownership with wordpress website
Google, Bing Verify ownership with wordpress

 

First install SEO Meta Tags wordpress plugin. On right side menu you will find “Webmaster Tools” page. Add your meta tags here. It will add best of meta tags to you wordpress site. This plugin will add best of SEO meta tags to your wordpress website. It will boost your wordpress website SEO in two weeks.

 

how to reduce bounce rate google analytics in wordpress

Page bounce rate is many time discussed in many article. Here we shown, how to reduce bounce rate google analytics in wordpress. Showed tricks for reduce bounce rate. My site was having high bounce rate always. I tried many tricks for solving the issue. Then I read many article about bounce rate. how google analytics calculating bounce rate.

I was recently told that some people use event tracking to find a truer bounce rate. Yes. You can reduce bounce rate by using some adding some javascript event to wordpress site. I found nice wordpress plugin which will help us to reduce bounce rate.

how to reduce bounce rate google analytics in wordpress

Reduce Bounce Rate

how to reduce bounce rate google analytics in wordpress
how to reduce bounce rate google analytics in wordpress

Get the real Time On Site and Bounce Rate in Google Analytics. Google Analytics calculates the Time On Site based on the length of time between a user entering your site and their last page view. This won\’t give you the REAL Time on Site and Bounce Rate stats.

FEATURES

  • Old and new tracking codes are supported
  • Code placement choice between header and footer
  • Track page scrolls
  • Change time event frequency
  • Set maximum tracking time
  • Disable for administrator role

Worst case scenario A visitor is very interested in one of your pages and takes 2 minutes and 13 seconds to read the article. After this he bookmarks the page and leaves. This visitor stayed 2 minutes and 13 seconds on your page, but never interacted with it. To Google that is a bounce! And bounced visits are marked 0:00 Time on Site. Not fair, right?

Another bad scenario A visitor goes to your website and stays 1 minute and 11 seconds on the first page. Then, he goes to a second page where he stays 1 minute and 12 seconds. Without any interaction on this page, he leaves. Since Google doesn’t know how long your visitor stayed on the second page, Google will add only the time the visitor spent on the first page to Analytics. Not fair, right?

My Review about Reduce Bounce Rate wordpress plugin

We installed this plugin and we found really good impact. Our websites bounce rate started reducing. It takes one or two weeks to see impact on google analytics page. Here In this article, we given screen shot of our google analytics page.

how to add h1 tag in wordpress homepage in theme

As a SEO specialist, We know the importance of h1 and h2 tag in wordpress website. Here we will show you, how to add h1 tag to wordpress homepage in theme code.

how to add h1 tag in wordpress homepage in theme

There are many custom wordpress themes which has poor SEO. We need check every aspect of SEO friendliness of wordpress theme. recently, we faced same issue with one of our site. When we checked the website in SEO doctor  Firefox addon. We did not find h1 tag on homepage. We got the following message.

 

h1 tag missing from homepage
how to add h1 tag in wordpress homepage in theme

When, we checked message. We found following error.

“Fail”,”H1 tag”,”* You have no H1 tags”
“Fail”,”H2 tag”,”* 10 H2 tags found before/without H1 (“Demo post 12″)”

Many custom developer talking about following solution. This will not display h1 to a visitor but will to a search engine.

<h1 style="display: none;"><!--?php the_title(); ?-->

 But we are not agree with above solution. do not use above solution. Google and other search engine did not consider hidden text or very small font words.

Solution

On Home page, For post title tag you should h1 tag. If you use multiple h1 tags in single webpage, that is not harmful. You should use rel bookmark in tag. For home page use following code.


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php if ( is_single() ) : ?>
<h1 class="entry-title"><!--?php the_title(); ?-->
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php else : ?>
<h1 class="entry-title">
php the_permalink(); ?>" rel="bookmark"><!--?php the_title(); ?-->
</h1>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endif; // is_single() ?>

Why Rel bookmark is used?

REL=Bookmark Bookmarks are used to provide direct links to key entry points into an extended document. The TITLE attribute may be used to label the bookmark. Several bookmarks may be defined in each document, and provide a means for orienting users in extended documents.

Reference Taken from : http://www.w3.org/MarkUp/html3/dochead.html

Conclusion

You can use style or classes as per your theme requirement.  The h1 is used in header.php for Custom Logo / Site Title, so there should be a H1 there. But If you used only logo image and not used h1 tag on home page than above issue will happen. You can use multiple h1 tags in one webpage. You can check wordpress core themes and their code and refer it. It has best SEO practice followed.

In core wordpress themes, We can see multiple H1 tags with rel bookmark element. So you can use above code in your wordpress theme and increase your website SEO.