How to create a permalink of custom post type with same slug as custom taxonomy?

Hello Everyone!

I hope you are doing well.

This time I am going to share one more useful knowledge to all wordpress developers who want to create a new custom url with same slug of custom taxonomy and custom post type.

I am going here to create a new custom post type “my_articles” with their custom taxonomy “my_article_term”. You can use your own custom post type name at place of “my_articles”.

Please follow given below steps:

Step-1

Create a new custom post type

/*-------------------------------------------------
 Sart Articles Post Type
------------------------------------------------- */
if(!function_exists('my_acticle_post_type_func')){
	function my_acticle_post_type_func()
	{

		$labels = array(
			'name' => __( 'Article', 'virtualemployee' ),
			'singular_name' => __( 'Article', 'virtualemployee' ),
			'add_new' => __( 'Add New', 'virtualemployee' ),
			'add_new_item' => __( 'Add New Article', 'virtualemployee' ),
			'edit_item' => __( 'Edit Article', 'virtualemployee' ),
			'new_item' => __( 'New Article', 'virtualemployee' ),
			'view_item' => __( 'View Article', 'virtualemployee' ),
			'search_items' => __( 'Search Article', 'virtualemployee' ),
			'not_found' => __( 'No Article Found', 'virtualemployee' ),
			'not_found_in_trash' => __( 'No article Found In Trash', 'virtualemployee' ),
			'parent_item_colon' => '',
			'menu_name' => __( 'Article', 'virtualemployee' )
		);
		
		$args = array(
			'labels' 			 => $labels,
			'menu_icon' 		 => 'dashicons-admin-post',
			'public'             => true,
			'publicly_queryable' => true,
			'show_ui'            => true,
			'show_in_menu'       => true,
			'query_var'          => true,
			'hierarchical'       => true,
			'menu_position'      => null,
			'rewrite' => array( 'slug' => 'articles/%my_article_term%', 'with_front' => false ),
			'has_archive' => 'articles',
			'supports' => array( 'title', 'editor','thumbnail', 'page-attributes', 'comments', 'author')
		);
		

		 register_post_type('my_articles', $args);
	}
}
add_action('init', 'my_acticle_post_type_func');

/*-------------------------------------------------
 End Articles Post Type
------------------------------------------------- */

Step -2

Create a new custom taxonomy

/*-------------------------------------------------
 Start Article Taxonomy
------------------------------------------------- */
// hook into the init action and call create_my_article_taxonomies when it fires
add_action( 'init', 'create_my_article_taxonomies', 0 );

if(!function_exists('create_my_article_taxonomies'))
{
	function create_my_article_taxonomies() {
		$labels = array(
			'name' 				=> __('Article Categories', 'virtualemployee'),
			'singular_name' 	=> __('Article', 'virtualemployee'),
			'search_items'  	=>  __('Search Categories', 'virtualemployee'),
			'all_items' 		=> __('All Categories', 'virtualemployee'),
			'parent_item' 		=> __('Parent', 'virtualemployee'),
			'parent_item_colon' => __('Parent:', 'virtualemployee'),
			'edit_item' 		=> __('Edit Category', 'virtualemployee'),
			'update_item' 		=> __('Update Category', 'virtualemployee'),
			'add_new_item' 		=> __('Add New Category', 'virtualemployee'),
			'new_item_name' 	=> __('New Category', 'virtualemployee'),
			'menu_name' 		=> __('Categories', 'virtualemployee'),
		);
		$args = array(
			'hierarchical'      => true,
			'labels'            => $labels,
			'show_ui'           => true,
			'show_admin_column' => true,
			'query_var'         => true,
			'rewrite' => array( 'slug' => 'articles', 'with_front' => false ),
		);
	register_taxonomy( 'my_article_term', 'my_articles', $args );  
	}
}
/*-------------------------------------------------
 End Articles Taxonomy
------------------------------------------------- */

Step-3

Generate new permalink for your newly created post type

/*-------------------------------------------------
 Start custom permalink
------------------------------------------------- */
function create_custom_permalinks( $post_link, $post ){
    if ( is_object( $post ) && $post->post_type == 'my_articles' ){
        $terms = wp_get_object_terms( $post->ID, 'my_article_term' );
        if( $terms ){
            return str_replace( '%my_article_term%' , $terms[0]->slug , $post_link );
        }
    }
    return $post_link;
}
add_filter( 'post_type_link', 'create_custom_permalinks', 1, 2 );
/*-------------------------------------------------
 End custom permalink
------------------------------------------------- */

URL Preview

  1. yourwebsite.com/articles/ => archive page
  2. yourwebsite.com/articles/%category%/ => custom taxonomy page
  3. yourwebsite.com/articles/%category%/%postname%/ => custom post

I hope you will enjoy this.

Advertisements
Tagged with: , , , , ,
Posted in Wordpress

Get flat 20% discount on wordpress best Social Share plugin

Hi There,

Get flat 20% discount on addons on the occasion of completing 3 Lakhs downloads of wordpress best social share plugin 

Video Demo : https://youtu.be/QUnxtCe95Ww

“Pay one time use lifetime!! “

Offer valid for limited period, so hurry up!!!!

Posted in Wordpress

Released one more new wordpress plugin “SEO Manager”

Hello There,

There are some SEO plugin already on wordpress site but few popular plugin authors have changed their code and added some necessary features (meta keywords) in PRO version.  That’s why we decided to provide a best SEO Manager plugin to our users with all the necessary features in a free version.

Finally today, we have released a new wordpress plugin “SEO Manager”. I want to let you all know that this is a very light weight plugin with all your necessary SEO meta fields like Meta Title, Meta Description, Meta Keywords….etc.

https://wordpress.org/plugins/seo-manager/

The Best WordPress SEO Plugin

 

Hope you will enjoy using this plugin.

Tagged with: , , , ,
Posted in Wordpress

Get Latest Version (3.3) of CSBWFS PRO addon with 25% Discount!!


Merry Christmas and Happy New Year 2017 – 2018!

We are very pleased to announce a special Christmas deal for all of our amazing customers and supporters!

Get 25% discount on the purchase of addon at https://rgaddons.wordpress.com/custom-share-buttons-with-floating-sidebar-pro/ store during this special festival season.

This offer is available for a limited time (from 22 December 2017 until 1 January 2018), so make sure to note your date.

Grab this deal and enjoy savings!

Get the deal

Video Tutorial!!

Tagged with: , ,
Posted in Wordpress

Released our official youtube channel “MR Web Solution” !!

Hello Friends,

From last few years, We were getting request from our users to provide video tutorial and Officially today we have released our youtube channel, I hope you all will like our videos.

Please have a look on below link to visit our youtube channel.

https://www.youtube.com/channel/UCD2SOgxuD5PRbIMCv8r_q4A

Share our channel link with your friends and don’t forget to subscribe our channel for get to latest videos.

If you have any suggestions then please don’t forget to leave your suggestions in comment box,we will review that and try to implement.

Thanks Again For Your Support!!

Tagged with: ,
Posted in Social Media, Wordpress

How to implement google analytics event tracking in shopify?

How implement google analytics event tracking in shopify?

Hello Friends,

I hope you all are doing well.

I am here going to explains how to implement event tracking with analytics.js on your shopify website.

Generally we can implment google analytics event traking on our website in a easy way using jquery or js (Ref. https://developers.google.com/analytics/devguides/collection/analyticsjs/events).

If you are going to implement event tracking code on your shopify websites then you can’t add event traking in a normal way. For add to event traking code on shopify website, you will must have need to follow shopify inbuilt function ShopifyAnalytics.merchantGoogleAnalytics()

You have need to call event traking within shopify analytics function.

window.ShopifyAnalytics.merchantGoogleAnalytics = function() {
// tracking code will be add here
ga(‘send’, ‘event’, [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
}

Example : Add event traking for newsletter

Find newsletter.liquid files (Admin >> Theme >> Edit code >> Section ) and add given below code under {% if form.posted_successfully? %} conditon

/* implement google event traking code */
window.ShopifyAnalytics.merchantGoogleAnalytics = function() {
ga(‘send’, ‘event’, ‘Subscribe’, ‘click’, ‘subscribeforcode’, 1);
}

If you found this post helpful then please don’t forget to like our facebook page.

Enjoy Code!

Tagged with: , , , , ,
Posted in Shopify

Google Plus Remove Share Counts Options

Hello Friends,

I want let you know two years ago, Twitter had removed tweets counter and now Google plus 😦

This is very bad news for all customers who were using google plus share counter buttons to promote his site, his products, his articles…etc

Google Plus Official Announcement :

In a blog post published in the middle of June this year, John Nack announced that the Google+ button – the G+ button provided for blogs to share their +1 count – is changing.

“The G+1 button is shown billions of times per day on web pages around the world, so it’s important that it load as quickly and efficiently as possible. To make it easier for people to load and share the pages they’re interested in, we’ve created a simpler G+1 button sharing experience. Beginning in a few weeks, clicking the +1 button will open a streamlined new Google+ sharing dialog, and the G+1 button will no longer display a +1 count.”

So, a simpler share button means the Google +1 button, without any count attached to it.

 

Tagged with: , ,
Posted in Wordpress
Recent Posts
%d bloggers like this: