PurabTech is technical blog for Programmer and Coders
Author: Purab
I am Purab from India, Software development is my profession and teaching is my passion.
Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks.
Purab's Github Repo
Youtube Chanel Video Tutorials
Connect to on LinkedIn
wordpress tutorial, how to check custom post type in wordpress. Many we want to execute some code on custom post type or want to execute code on post. Many we want to execute some code on custom post type or some times we want to execute code on normal pages or post.
how to check custom post type in wordpress
So here is solution. You just need to just add following code into your functions.php file which you can find in your wordpress theme folder.
function check_custom_post_type() {
global $wp_query;
$post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and');
foreach ($post_types as $post_type ) {
if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
return true;
} else {
return false;
}
}
}
After this you can use following function in any wordpress file. For example you can use this method in single.php file.
if (check_custom_post_type()) {
//Current post is a custom post type
}
wordpress tutorial, how to check custom post type in wordpress. Many we want to execute some code on custom post type or want to execute code on post.
Normally people searching for best wordpress seo plugins, I shortlised best wordpress seo plugins which are really useful for every wordpress developers.
I am using wordpress since 2006 for my blogs and websites. Since I also written the wordpress plugins for SEO purpose. Still some wordpress plugins are really doing great work. SEO is very import facter for every website.
best wordpress seo plugins
I almost used every best wordpress seo plugins But I like following wordpress plugins due to some reasons. Personally I like the “WordPress SEO by Yoast” wordpress plugin for SEO purpose. It is simple to use. It is not impacting on your site performance. It takes less then 40% memory as compare the other seo plugins. Site performance is very for every website seo. Meta description and meta tags and seo title are equally important.
Boost your wordpress SEO: Full SEO features Meta Tags, webmaster tools settings, Social AuthorShip for Facebook, Twitter and Google Plus and XML sitemap
You can enter your meta keywords and description for your homepage and each post and pages.
This plugin will add different Meta description for each individual post as your excerpt of your post.
This will help your blog to rank better in google. You can easily increase your blog traffic using this plugin.
Following are the features:
Preview of Smart wordpress SEO – Home page Keywords and description
WebMaster Tool Verification Setting
Social Authorship for Google, Twitter and Facebook
XML sitemap setting
Image SEO setting
Eash Post or Page SEO title, Description and Keywords setting
best wordpress seo plugins ever which will increase site seo
Improve your WordPress SEO: Write better content and have a fully optimized WordPress site using the WordPress SEO plugin by Yoast.
Comments: This is very nice plugin for SEO. It takes less memory as compare to other best wordpress seo plugins. I personally using this plugin in my site. This plugin has not many features like other best wordpress seo plugins but this plugin is really fast. No memory leak issues with this plugin.
This all-in-one SEO plugin gives you control over title tags, noindex, meta tags, Open Graph, slugs, canonical, autolinks, 404 errors, rich snippets,
Comments: I love this plugin. This plugins I used for years. If you have good hosting solution then you should go for this plugin for seo. This is best ever and great plugin for seo. But only bad part is It takes lot of memory of your site almost 30% of memory will consumed by this plugin while each page loading. Still I can recommend this plugin for SEO because It has really great result in SEO with wordpress.
WordPress SEO plugin to automatically optimize your WordPress blog for Search Engines.
Comments: This plugin is really oldest great seo tool for wordpress. This plugin I used for some time. It has great features. Helpful to SEO. Many bloggers are still loving this wordpress plugin and using it. This plugin also consume your server memory big time while each page loading. Performance is very important when you are using any wordpress plugin.
You can enter your meta keywords and description for your homepage. Same like best wordpress seo plugins, this is also great and simple and very light seo plugin which is written by me.
This plugin will add different Meta description for each individual post as your excerpt of your post. This will help your blog to rank better in google. You can easily increase your blog traffic using this plugin.
Comments: This plugin has minimal features for SEO but still most important seo features are present in this plugin. This plugin will not consume your site memory. This plugin is super fast. This plugin is very easy to use in your site. They looked for performance of site. Using this plugin you can increase the seo without effecting the site performance.
What People are doing for SEO
Normally people are searching for best wordpress seo plugins, install wordpress seo plugins, all in one seo wordpress plugin, wordpress seo optimization, yoast seo, wp seo plugin, all in one seo vs yoast, seo ultimate vs yoast. I shortlised the best ever wordpress seo plugin which are really useful for every wordpress developers. If you have doubts about wordpress SEO then you can write to me.
WordPress tutorial for plugin developers, add wordpress plugin header image in WordPress Plugins listing page. wordpress is allowing to add header image. This is very old thing still I am bringing up again. From Jan 2012 wordpress is allowing to add the wordpress plugin header image in wordpress plugin listing.
add wordpress plugin header image in WordPress Plugins listing
After adding image to assets folder to SVN root. Plugin image will appear after half hour.
As an experiment we’ve turned on custom hThis is very old thing still I am bringing up again. From Jan 2012 wordpress is allowing to add the wordpress plugin header image in wordpress plugin listing.
After adding image to assests folder to SVN root. Plugin image will appear after half hour.
As an experiment we’ve turned on custom headers for the plugin directory. If you’d like to try out this feature:
Make a 772×250 pixel jpeg or png. (No animated GIFs. 🙂 )
Check it in to your plugin’s SVN directory with the path assets/banner-772×250.(jpg|
png). Note that the assets directory is added to your plugin’s root directory, not trunk.
On the next plugin directory refresh (every 15 minutes or so) you should see your image start showing up on the page.
eaders for the plugin directory. If you’d like to try out this feature:
Make a 772×250 pixel jpeg or png. (No animated GIFs. 🙂 )
Check it in to your plugin’s SVN directory with the path assets/banner-772×250.(jpg|
png). Note that the assets directory is added to your plugin’s root directory, not trunk.
On the next plugin directory refresh (every 15 minutes or so) you should see your image start showing up on the page.
add wordpress plugin header image in WordPress Plugins listing
Spam comments are most irritating for bloggers. Reading the all comments and their content and desire. If Comment author URL is bigger then you should consider that comment as Spam comment for sure. Many times I observed, spammer always try to add their site URL in Author URL.
comment Author URL is bigger in WordPress
Using following code you can protect your site from spam commenters. Open your functions.php file from your theme folder and just copy/paste the following code into that.
Following code will automatically mark the comments as spam where author URL is longer than 60 chars.
SVG format is very important for chants and graphs. For admin orientated sites. There are many HTML admin templates which purely based on svg format. In HTML5 format SVG based graphs are too important. SVG is a language for describing two-dimensional vector graphics in XML. SVG stands for Scalable Vector Graphics.SVG defines graphics in XML format.
What is SVG?
SVG stands for Scalable Vector Graphics
SVG is used to define vector-based graphics for the Web
SVG defines the graphics in XML format
SVG graphics do NOT lose any quality if they are zoomed or resized
Every element and every attribute in SVG files can be animated
SVG is a W3C recommendation
SVG integrates with other W3C standards such as the DOM and XSL
SVG Advantages
Advantages of using SVG over other image formats (like JPEG and GIF) are:
SVG images can be created and edited with any text editor
SVG images can be searched, indexed, scripted, and compressed
SVG images are scalable
SVG images can be printed with high quality at any resolution
SVG images are zoomable (and the image can be zoomed without degradation)
SVG is an open standard
SVG files are pure XML
svg format is You can add this support by adding following in your functions.php file which you find in your wordpress theme folder.WordPress uploader does not support of SVG format files. Adding SVG upload functionality to WordPress. using our code your can use svg functionality in wordpress.
Adding SVG upload functionality to WordPress site
After adding following code you will be able to upload the svg file into your wordpress site or blog.
Every custom them has option, Managing or change wordpress author slug is common in wordpress sites. you can use our come snippet for this for change author URL base. Some times you want to change the worpdress author URL slug then you can use the following code:
You need to add code into functions.php of your wordpress theme.
how to change wordpress author slug or URL base
That will change the default yoursite.com/author/authorname to yoursite.com/author-profile/authorname.
So you can change this to user or anything that you would like.
add_action('init', 'change_wp_author_base');
function change_wp_author_base() {
global $wp_rewrite;
$author_slug = 'author-profile'; // change author slug name
$wp_rewrite->author_base = $author_slug;
}
Many people use the scaled image for thumbnail image. Instead of that croping image the proper size and showing that is nice. Crop Uploaded image without plugin is supported by wordpress itself so do not use any third-party plugin for this.
crop uploaded image in wordpress
You can use the following code in your functions.php file:
Users always use the search the keywords in wordpress sites. Many times clients wish about this functionality. If there is only one result came from search result than user should redirect to single landing post.
Search result is single than redirect to wordpress post
If there is Search result is single then redirect to wordpress should redirect to single landing post.
You should open the functions.php file and put following code in functions.php file.
<pre>add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
}
}
}
Search result is single than redirect to wordpress post
Many people using featured images in there blog or sites. Setting default featured image using wordpress plugin for every post is not possible for some times so creating the one default image and set that default image for all the posts is really good idea. Some times If you not have the default image then it is possible to break your wordpress theme or it does not look nice without featured image. In this article I will show you how to Setting default featured image using wordpress plugin.
Setting default featured image using wordpress plugin
Setting default featured image using wordpress plugin for post is not possible for some times so creating default image, for all posts is really good idea.
But still you want to set the default featured image using following wordpress plugin.
Add a default featured image to the media settings page. This featured image will show up if no featured image is set. Simple as that.
For exceptions and to see which functions to use see the FAQ.
My chosen featured image doesn’t show, why isn’t it working?
This plugin can’t guarantee that it works. That depends on the themes. Still I want to know if it fails, so contact me
Which functions can I use to display the featured image?
The plugin uses the default WordPress functions the_post_thumbnail or get_the_post_thumbnail. has_post_thumbnail will always return true. get_post_thumbnail_id will return the ID set on the post or the DFI you set.
Can I exclude a page or give it a different image?
yes. you can exclude all kinds of things with the conditional tags. A few examples which you can paste in your functions.php
Dont use a featured image on page 5
function dfi_skip_page( $dfi_id ) {
if ( is_single( 5 ) || get_the_ID() == 5 ) {
return 0; // invalid id
}
return $dfi_id; // the original featured image id
}
add_filter('dfi_thumbnail_id', 'dfi_skip_page' );
Use a different image on the “book” posttype. The ID of the image is 12
function dfi_posttype_book( $dfi_id ) {
if ( is_singular( 'book' ) || get_post_type() == 'book' ) {
return 12; // the image id
}
return $dfi_id; // the original featured image id
}
add_filter('dfi_thumbnail_id', 'dfi_posttype_book' );
Use a different image on certain categories
function dfi_category( $dfi_id ) {
if ( has_category( 'category-slug' ) ) {
return 13; // the image id
} else if ( has_category( 'other_category' ) ) {
return 14; // the image id
}
return $dfi_id; // the original featured image id
}
add_filter('dfi_thumbnail_id', 'dfi_category' );
Can I change the HTML of the image returned?
yes you can with the filter dfi_thumbnail_html.
function dfi_add_class($html, $post_id, $default_thumbnail_id, $size, $attr) {
// add a class to the existing class list
$attr['class'] .= ' my-class';
return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
}
add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );
First thing you need to do is install and activate the Default Featured Image plugin. Upon activation, the plugin adds an option under Setttings » Media to choose a default image.
Setting default featured image using wordpress plugin
Some times you need people want to add guest author’s articles in your site. So add guest author custom field in wordpress using code so that meta field will be useful to you in future.
how to add guest author custom field in wordpress admin
If you want to add the guest author custom field in wordpress admin. you can use the following code.
You need to open your functions.php file put following code in that.