[fusion_builder_container type=”flex” hundred_percent=”no” hundred_percent_height=”no” hundred_percent_height_scroll=”no” align_content=”stretch” flex_align_items=”flex-start” flex_justify_content=”flex-start” hundred_percent_height_center_content=”yes” equal_height_columns=”no” container_tag=”div” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” border_style=”solid” box_shadow=”no” box_shadow_blur=”0″ box_shadow_spread=”0″ gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” absolute=”off” absolute_devices=”small,medium,large” sticky=”off” sticky_devices=”small-visibility,medium-visibility,large-visibility” sticky_transition_offset=”0″ scroll_offset=”0″ animation_direction=”left” animation_speed=”0.3″ filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ type=”1_1″ layout=”1_1″ align_self=”auto” content_layout=”column” align_content=”flex-start” valign_content=”flex-start” content_wrap=”wrap” center_content=”no” target=”_self” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” order_medium=”0″ order_small=”0″ hover_type=”none” border_style=”solid” box_shadow=”no” box_shadow_blur=”0″ box_shadow_spread=”0″ background_type=”single” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ animation_direction=”left” animation_speed=”0.3″ last=”true” border_position=”all” element_content=”” first=”true” min_height=”” link=””][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”2″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]
The Problem
[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”90px”]
Avada is a popular wordpress theme that offers a lot of features and pre-built websites, which helps people to rapidly build their own website right out of the box. Though it’s not as popular as before, mainly due to performance reason, Avada still has consistent support and large enough communities which still makes the theme an attractive choice.
Avada offers Portfolio feature which creates its own type of post and renders the post in a specific way. In WordPress point-of-view, this portfolio is a custom post type that differentiates itself from other default post types like: Posts, Pages, Attachments, etc. This way, Avada is able to make portfolio post type to behave and render in specific way.
[/fusion_text][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The first problem with portfolio feature is, although regular posts and portfolio posts are two different types of post, they are sharing a same permalink structure. This results in:
[/fusion_text][fusion_syntax_highlighter language=”txt” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px” border_color=”#ff285e”]aHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Jsb2cvaXMtYXZvY2Fkby1yZWFsbHktdGhhdC1nb29kLyAgICAgICAgIC8qIEJsb2cgUG9zdCAqLwpodHRwczovL2hhbnN1bmdzbWIuY28ua3IvYmxvZy9jYXNlcy9iYWQtY2FzZS1vZi1sb3ZpbmcteW91LyAgICAgICAgLyogUG9ydGZvbGlvIFBvc3QgKi8=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The /cases/ slug can be configured in Avada option.
Both of them are stemming from /blog/ slug because Setting -> Permalink -> Common Settings -> Custom Structure is /blog/%postname%/.
The ideal structure would be:
[/fusion_text][fusion_syntax_highlighter language=”txt” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”90px” border_color=”#00b223″]aHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Jsb2cvaXMtYXZvY2Fkby1yZWFsbHktdGhhdC1nb29kLyAgICAgICAgIC8qIEJsb2cgUG9zdCAqLwpodHRwczovL2hhbnN1bmdzbWIuY28ua3IvY2FzZXMvYmFkLWNhc2Utb2YtbG92aW5nLXlvdS8gICAgICAgICAgICAgLyogUG9ydGZvbGlvIFBvc3QgKi8=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The second problem, which is a following problem after the first one, is that custom post type slug and custom taxonomy slug can’t share a same prepending slug (in this case /cases/). Avada, by default, attaches 3 taxonomies to portfolio post type: category, skill, and tag. If any of these taxonomies has cases as their starting custom bases in Setting -> Permalink -> Optional, it will be directed to 404 Page Not Found page.
[/fusion_text][fusion_syntax_highlighter language=”txt” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px” border_color=”#ff285e”]aHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VzLyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIEEgY29sbGVjdGlvbiBvZiBwb3J0Zm9saW8gcG9zdHMgKi8KaHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VzL2JhZC1jYXNlLW9mLWxvdmluZy15b3UvICAgICAgICAgICAgIC8qIEEgc2luZ2xlIHBvcnRmb2xpbyBwb3N0ICovCmh0dHBzOi8vaGFuc3VuZ3NtYi5jby5rci9jYXNlcy9jYXRlZ29yaWVzL3NvbmcvICAgICAgICAgICAgICAgICAgICAvKiBUSElTIFJFU1VMVFMgSU4gNDA0IEVSUk9SISEhICovCmh0dHBzOi8vaGFuc3VuZ3NtYi5jby5rci9jYXNlX2NhdGVnb3JpZXMvc29uZy8gICAgICAgICAgICAgICAgICAgICAvKiBBIGNvbGxlY3Rpb24gb2YgcG9ydGZvbGlvIHBvc3RzIHdpdGggYSBjYXRlZ29yeSAnc29uZycgKi8KaHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2Vfc2tpbGxzL3ZvY2FsLyAgICAgICAgICAgICAgICAgICAgICAgIC8qIEEgY29sbGVjdGlvbiBvZiBwb3J0Zm9saW8gcG9zdHMgd2l0aCBhIHNraWxsICd2b2NhbCcgKi8KaHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VfdGFncy9yb2NrLyAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIEEgY29sbGVjdGlvbiBvZiBwb3J0Zm9saW8gcG9zdHMgd2l0aCBhIHRhZyAncm9jaycgKi8=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
I want all portfolio related elements (posts, taxonomies) to stem from /cases/.
The ideal structure would be:
[/fusion_text][fusion_syntax_highlighter language=”txt” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”75px” border_color=”#00b223″]aHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VzLyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIEEgY29sbGVjdGlvbiBvZiBwb3J0Zm9saW8gcG9zdHMgKi8KaHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VzL2JhZC1jYXNlLW9mLWxvdmluZy15b3UvICAgICAgICAgICAgIC8qIEEgc2luZ2xlIHBvcnRmb2xpbyBwb3N0ICovCmh0dHBzOi8vaGFuc3VuZ3NtYi5jby5rci9jYXNlcy9jYXRlZ29yaWVzL3NvbmcvICAgICAgICAgICAgICAgICAgICAvKiBBIGNvbGxlY3Rpb24gb2YgcG9ydGZvbGlvIHBvc3RzIHdpdGggYSBjYXRlZ29yeSAnc29uZycgKi8KaHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VzL3NraWxscy92b2NhbC8gICAgICAgICAgICAgICAgICAgICAgIC8qIEEgY29sbGVjdGlvbiBvZiBwb3J0Zm9saW8gcG9zdHMgd2l0aCBhIGNhdGVnb3J5ICd2b2NhbCcgKi8KaHR0cHM6Ly9oYW5zdW5nc21iLmNvLmtyL2Nhc2VzL3RhZ3Mvcm9jay8gICAgICAgICAgICAgICAgICAgICAgICAgIC8qIEEgY29sbGVjdGlvbiBvZiBwb3J0Zm9saW8gcG9zdHMgd2l0aCBhIGNhdGVnb3J5ICdyb2NrJyAqLw==[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”2″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]
Solution: First Problem
[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The reason why portfolio posts prepends custom permalink structure is because that’s the default setting when registering a new post type. Portfolio post type and taxonomy registration happens at /wp-content/plugins/fusion-core/includes/class-fusioncore-plugin.php.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]cmVnaXN0ZXJfcG9zdF90eXBlKAogICAgJ2F2YWRhX3BvcnRmb2xpbycsCiAgICBbCiAgICAgICAgJ2xhYmVscycgICAgICAgPT4gWwogICAgICAgICAgICAnbmFtZScgICAgICAgICAgICAgICAgICAgICA9PiBfeCggJ1BvcnRmb2xpbycsICdQb3N0IFR5cGUgR2VuZXJhbCBOYW1lJywgJ2Z1c2lvbi1jb3JlJyApLAogICAgICAgICAgICAnc2luZ3VsYXJfbmFtZScgICAgICAgICAgICA9PiBfeCggJ1BvcnRmb2xpbycsICdQb3N0IFR5cGUgU2luZ3VsYXIgTmFtZScsICdmdXNpb24tY29yZScgKSwKICAgICAgICAgICAgJ2FkZF9uZXdfaXRlbScgICAgICAgICAgICAgPT4gX18oICdBZGQgTmV3IFBvcnRmb2xpbyBQb3N0JywgJ2Z1c2lvbi1jb3JlJyApLAogICAgICAgICAgICAnZWRpdF9pdGVtJyAgICAgICAgICAgICAgICA9PiBfXyggJ0VkaXQgUG9ydGZvbGlvIFBvc3QnLCAnZnVzaW9uLWNvcmUnICksCiAgICAgICAgICAgICdpdGVtX3B1Ymxpc2hlZCcgICAgICAgICAgID0+IF9fKCAnUG9ydGZvbGlvIHB1Ymxpc2hlZC4nLCAnZnVzaW9uLWNvcmUnICksCiAgICAgICAgICAgICdpdGVtX3B1Ymxpc2hlZF9wcml2YXRlbHknID0+IF9fKCAnUG9ydGZvbGlvIHB1Ymxpc2hlZCBwcml2YXRlbHkuJywgJ2Z1c2lvbi1jb3JlJyApLAogICAgICAgICAgICAnaXRlbV9yZXZlcnRlZF90b19kcmFmdCcgICA9PiBfXyggJ1BvcnRmb2xpbyByZXZlcnRlZCB0byBkcmFmdC4nLCAnZnVzaW9uLWNvcmUnICksCiAgICAgICAgICAgICdpdGVtX3NjaGVkdWxlZCcgICAgICAgICAgID0+IF9fKCAnUG9ydGZvbGlvIHNjaGVkdWxlZC4nLCAnZnVzaW9uLWNvcmUnICksCiAgICAgICAgICAgICdpdGVtX3VwZGF0ZWQnICAgICAgICAgICAgID0+IF9fKCAnUG9ydGZvbGlvIHVwZGF0ZWQuJywgJ2Z1c2lvbi1jb3JlJyApLAogICAgICAgIF0sCiAgICAgICAgJ3B1YmxpYycgICAgICAgPT4gdHJ1ZSwKICAgICAgICAnaGFzX2FyY2hpdmUnICA9PiB0cnVlLAogICAgICAgICdyZXdyaXRlJyAgICAgID0+IFsKICAgICAgICAgICAgJ3NsdWcnID0+ICRmdXNpb25fc2V0dGluZ3NfYXJyYXlbJ3BvcnRmb2xpb19zbHVnJ10sICAgICAgLy8gd2l0aF9mcm9udCBzaG91bGQgYmUgc2V0IHRvIGZhbHNlIGhlcmUhISEKICAgICAgICBdLAogICAgICAgICdzaG93X2luX3Jlc3QnID0+IHRydWUsCiAgICAgICAgJ3N1cHBvcnRzJyAgICAgPT4gWyAndGl0bGUnLCAnZWRpdG9yJywgJ2V4Y2VycHQnLCAnYXV0aG9yJywgJ3RodW1ibmFpbCcsICdjb21tZW50cycsICdyZXZpc2lvbnMnLCAnY3VzdG9tLWZpZWxkcycsICdwYWdlLWF0dHJpYnV0ZXMnLCAncG9zdC1mb3JtYXRzJyBdLAogICAgICAgICdjYW5fZXhwb3J0JyAgID0+IHRydWUsCiAgICBdCik7[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
When Avada registers portfolio post type, it does not explicitly set with_front to false, but just leave it empty which defaults to true.
To disable $front prepending the permastruct:
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]J3Jld3JpdGUnICAgICAgPT4gWwogICAgJ3NsdWcnID0+ICRmdXNpb25fc2V0dGluZ3NfYXJyYXlbJ3BvcnRmb2xpb19zbHVnJ10sCiAgICAnd2l0aF9mcm9udCcgPT4gZmFsc2UsICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBObyBtb3JlIHByZXBlbmRpbmchISEgCl0s[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”45px”]
But be advised that source code should not be edited directly. It will easily be overwritten when there’s an update and it will cause unexpected problems.
Fortunately, WordPress provides hooks that is suitable for this kind of job. There are several hooks that can do the job, and register_post_type_args is the one that’s most appropriate for this task.
Where can hooks be used then?
[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”3″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]
Creating a custom plugin
[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
When site-wide modification is made, it’s often recommended to make changes with theme’s function.php or create a custom plugin. However, making changes in function.php is not recommended as theme updates will overwrite the file. So unless the website uses its own developed theme, it is recommended to make changes through a custom plugin.
This article will not cover much on the topic of custom plugin, but just show how to make a quick custom plugin. For more details, you can follow WordPress Plugin Development Guide.
To create a custom plugin, go to /wp-content/plugins/ and create your own folder named after your plugin. In this example, the folder will be named portfolio-slug and its plugin file will be named porfolio-slug.php.
Open /wp-content/plugins/portfolio-slug/portfolio-slug.php (the file you just created) with preferred text editor and copy and paste the code below:
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]PD9waHAKCi8qClBsdWdpbiBOYW1lOiBQb3J0Zm9saW8gU2x1ZwpQbHVnaW4gVVJJOiBodHRwczovL2hhbnN1bmdzbWIuY28ua3IKRGVzY3JpcHRpb246IFRoaXMgcGx1Z2luIHdpbGwgY2hhbmdlIGhvdyBBdmFkYSBwb3J0Zm9saW8sIG9yIGN1c3RvbSBwb3N0IHR5cGUgYmVoYXZlcwpWZXJzaW9uOiAxLjAKQXV0aG9yOiBPUk1FRUhZVU5HS0VVTiBDSEEKTGljZW5zZTogR1BMdjIgb3IgbGF0ZXIKKi8=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The Plugin Name is the only required header field, so you can erase rest of the field if you want to. However, it’s strongly recommended to fill out Description field and Author field for readability.
Save the file and go to WordPress admin page -> Plugins, and you’ll see your custom plugin among other plugins like the picture below.
[/fusion_text][fusion_imageframe custom_aspect_ratio=”100″ lightbox=”no” linktarget=”_self” align_medium=”none” align_small=”none” align=”center” hover_type=”none” caption_style=”below” caption_align_medium=”none” caption_align_small=”none” caption_align=”center” caption_title_tag=”div” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ image_id=”18326|full” caption_title=”Never mind Korean here!” caption_title_color=”#888888″ caption_margin_bottom=”15px” fusion_font_variant_caption_title_font=”400″ fusion_font_family_caption_title_font=”Pretendard Regular”]https://hansungsmb.co.kr/wp-content/uploads/2021/12/plugin_list.png[/fusion_imageframe][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”45px”]
Activate the plugin, and you’re ready to use hooks!
[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”3″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]Using hooks[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
There are two types of hooks: Action and Filter. Again, this article is not going to cover great detail on this topic. For more information, take a look at WordPress Plugin Developer Handbook.
The hook register_post_type_args is a filter type that can alter the arguments when registering a post type. To add filter, simply use add_filter function.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]YWRkX2ZpbHRlciggc3RyaW5nICRob29rX25hbWUsIGNhbGxhYmxlICRjYWxsYmFjaywgaW50ICRwcmlvcml0eSA9IDEwLCBpbnQgJGFjY2VwdGVkX2FyZ3MgPSAxICk=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The add_filter function will take the name of the filter hook as first argument, function to execute when triggered (callback function) as second, filter execution priority as third, and the number of arguments of callback function as fourth.
Open plugin-slug.php in text editor and add a line:
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]YWRkX2ZpbHRlcigncmVnaXN0ZXJfcG9zdF90eXBlX2FyZ3MnLCAnY2hhbmdlX2F2YWRhX3BvcnRmb2xpb19zbHVnJywgMTAsIDIpOw==[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
This means that filter has been added to register_post_type_args hook and it will execute a function called change_avada_portfolio_slug. The filter has a priority of 10 (lowest) and change_avada_portfolio_slug function will take 2 arguments.
change_avada_portfolio_slug function has not been declared yet. Declare a function before/after add_filter line:
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]ZnVuY3Rpb24gY2hhbmdlX2F2YWRhX3BvcnRmb2xpb19zbHVnKCRhcmdzLCAkcG9zdF90eXBlKQp7CiAgICBpZiAoJHBvc3RfdHlwZSA9PT0gJ2F2YWRhX3BvcnRmb2xpbycpIHsKICAgICAgICAkYXJnc1sncmV3cml0ZSddWyd3aXRoX2Zyb250J10gPSBmYWxzZTsKICAgIH0KICAgIHJldHVybiAkYXJnczsKfQo=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
The function has two parameters, $args and $post_type.
$args contains all the arguments when new post type is registered like in /wp-content/plugins/fusion-core/includes/class-fusioncore-plugin.php, and it has rewrite property that needs to modified.
$post_type tells which post type is being registered.
There are many other post types being registered when WordPress is running and this hook will run every time when such post types are being registered. if statement is required to restrict the function to only work on avada_portfolio post type.
The function is basically saying, “If the post being registered is called avada_portfolio, set the property with_front of rewrite in $args to false. Then return $args for WordPress to carry on with its work.”
Save the file and go to Admin page -> Settings -> Permalink.
Without making changes in settings, click Save Changes. This will refresh the permastructure.
Create a new portfolio post and you’ll see the result of your work:
[/fusion_text][fusion_imageframe custom_aspect_ratio=”100″ lightbox=”no” linktarget=”_self” align_medium=”none” align_small=”none” align=”center” hover_type=”none” caption_style=”off” caption_align_medium=”none” caption_align_small=”none” caption_align=”none” caption_title_tag=”2″ animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ image_id=”18328|full” fusion_font_variant_caption_title_font=”400″ margin_bottom=”75px”]https://hansungsmb.co.kr/wp-content/uploads/2021/12/new_portfolio_post.png[/fusion_imageframe][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”2″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]
Solution: Second Problem
[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
Let’s cut to the chase here. it is possible for posts and taxonomies to use a same slug. However this has to be done in very specific way.
When a custom post type and its custom taxonomies are registered, taxonomies have to be registered first and then a custom post type in order to let them share a slug.
The problem is, when Avada registers its portfolio post type, it registers a post type first and then its taxonomies, as shown below:
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]aWYgKCAhIGNsYXNzX2V4aXN0cyggJ0Z1c2lvbl9TZXR0aW5ncycgKSB8fCAnMCcgIT09ICRmdXNpb25fc2V0dGluZ3MtPmdldCggJ3N0YXR1c19mdXNpb25fcG9ydGZvbGlvJyApICkgewogICAgcmVnaXN0ZXJfcG9zdF90eXBlKCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBQT1NUIFRZUEUgRklSU1QhISEKICAgICAgICAnYXZhZGFfcG9ydGZvbGlvJywKICAgICAgICBbCiAgICAgICAgICAgIC8vIEFycmF5IG9mIGltcG9ydGFudCBwcm9wZXJ0aWVzIAogICAgICAgIF0KICAgICk7CiAgICByZWdpc3Rlcl90YXhvbm9teSggICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIENBVEVHT1JZIFNFQ09ORAogICAgICAgICdwb3J0Zm9saW9fY2F0ZWdvcnknLAogICAgICAgICdhdmFkYV9wb3J0Zm9saW8nLAogICAgICAgIFsKICAgICAgICAgICAgLy8gQXJyYXkgb2YgaW1wb3J0YW50IHByb3BlcnRpZXMKICAgICAgICBdCiAgICApOwogICAgcmVnaXN0ZXJfdGF4b25vbXkoICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBTS0lMTFMgVEhJUkQKICAgICAgICAncG9ydGZvbGlvX3NraWxscycsCiAgICAgICAgJ2F2YWRhX3BvcnRmb2xpbycsCiAgICAgICAgWwogICAgICAgICAgICAvLyBBcnJheSBvZiBpbXBvcnRhbnQgcHJvcGVydGllcwogICAgICAgIF0KICAgICk7CiAgICByZWdpc3Rlcl90YXhvbm9teSggICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFRBR1MgRk9VUlRICiAgICAgICAgJ3BvcnRmb2xpb190YWdzJywKICAgICAgICAnYXZhZGFfcG9ydGZvbGlvJywKICAgICAgICBbCiAgICAgICAgICAgIC8vIEFycmF5IG9mIGltcG9ydGFudCBwcm9wZXJ0aWVzCiAgICAgICAgXQogICAgKTsKfQ==[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”45px”]
There are filters and actions that can alter the values being passed, but there’s no such hooks that can alter the sequence of registration.
Here is how this article will tackle this problem:
- Instead of trying to change the outcome during registration process, wait for all the registrations to finish.
- Unregister the registered post type and taxonomies.
- Re-register the post type and taxonomies in specific order.
[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”3″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]1. Wait for registrations to finish[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
WordPress hooks don’t just randomly fire any time they want. They have an acceptable sequence. For example, muplugins_loaded is one of the earliest fired hook that runs when must-use plugins are loaded. To wait out for fusion-core plugin to finish its registration, init hook (fires when WordPress is initialized) is not enough.
wp_loaded hook fires once WordPress, all plugins, and the theme are fully loaded and instantiated. To setup the hook, open portfolio-slug.php with a text editor and add a line:
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]YWRkX2FjdGlvbignd3BfbG9hZGVkJywgJ3VucmVnaXN0ZXJfYW5kX3JlcmVnaXN0ZXJfYXZhZGFfcG9ydGZvbGlvJyk7[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
wp_loaded is an action type hook that can be added with add_action function.
Declare unregister_and_reregister_avada_portfolio function.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”45px”]ZnVuY3Rpb24gdW5yZWdpc3Rlcl9hbmRfcmVyZWdpc3Rlcl9hdmFkYV9wb3J0Zm9saW8oKSAgICAgICAgIC8vZG9lc24ndCB0YWtlIGFueSBhcmd1bWVudHMKewogIAp9[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”3″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]2. Unregister the post type and taxonomies[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
To unregister a post type, use unregister_post_type function.
To unregister a taxonomy, use unregister_taxonomy function.
But before unregisteration, post type and taxonomy should be stored as an object so that it can be used when re-registering.
To get existing post type as an object, use get_post_type_object function.
To get existing taxonomy as an object, use get_taxonomy function.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”45px”]ZnVuY3Rpb24gdW5yZWdpc3Rlcl9hbmRfcmVyZWdpc3Rlcl9hdmFkYV9wb3J0Zm9saW8oKSAgICAgICAgIC8vZG9lc24ndCB0YWtlIGFueSBhcmd1bWVudHMKewogICAgLy8gU3RvcmUgcG9zdCB0eXBlIGFuZCB0YXhvbm9taWVzIGFzIGFuIG9iamVjdAogICAgJHBvc3RfdHlwZV9vYmogPSBnZXRfcG9zdF90eXBlX29iamVjdCgnYXZhZGFfcG9ydGZvbGlvJyk7CiAgICAkY2F0ZWdvcnlfb2JqID0gZ2V0X3RheG9ub215KCdwb3J0Zm9saW9fY2F0ZWdvcnknKTsKICAgICRza2lsbHNfb2JqID0gZ2V0X3RheG9ub215KCdwb3J0Zm9saW9fc2tpbGxzJyk7CiAgICAkdGFnc19vYmogPSBnZXRfdGF4b25vbXkoJ3BvcnRmb2xpb190YWdzJyk7CgogICAgLy8gVW5yZWdpc3RlciBwb3N0IHR5cGUgYW5kIHRheG9ub21pZXMKICAgIHVucmVnaXN0ZXJfcG9zdF90eXBlKCdhdmFkYV9wb3J0Zm9saW8nKTsKICAgIHVucmVnaXN0ZXJfdGF4b25vbXkoJ3BvcnRmb2xpb19jYXRlZ29yeScpOwogICAgdW5yZWdpc3Rlcl90YXhvbm9teSgncG9ydGZvbGlvX3NraWxscycpOwogICAgdW5yZWdpc3Rlcl90YXhvbm9teSgncG9ydGZvbGlvX3RhZ3MnKTsKfQ==[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”3″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]
3. Re-register the post type and taxonomies
[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
To register a post type, use register_post_type function.
To register a taxonomy, use register_taxonomy function.
Fortunately, these functions can receive objects saved by get_post_type_object and get_taxonomy functions.
Register taxonomies first, and then a post type.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]cmVnaXN0ZXJfdGF4b25vbXkoJ3BvcnRmb2xpb19jYXRlZ29yeScsICdhdmFkYV9wb3J0Zm9saW8nLCAkY2F0ZWdvcnlfb2JqKTsKcmVnaXN0ZXJfdGF4b25vbXkoJ3BvcnRmb2xpb19za2lsbHMnLCAnYXZhZGFfcG9ydGZvbGlvJywgJHNraWxsc19vYmopOwpyZWdpc3Rlcl90YXhvbm9teSgncG9ydGZvbGlvX3RhZ3MnLCAnYXZhZGFfcG9ydGZvbGlvJywgJHRhZ3Nfb2JqKTsKcmVnaXN0ZXJfcG9zdF90eXBlKCdhdmFkYV9wb3J0Zm9saW8nLCAkcG9zdF90eXBlX29iaik7[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
There is a side effect though, Featured Image setting disappears.
In order to enable it, and prevent other possible side effects, add a line before registering the custom post type.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]YWRkX3Bvc3RfdHlwZV9zdXBwb3J0KCdhdmFkYV9wb3J0Zm9saW8nLCBbJ3RpdGxlJywgJ2VkaXRvcicsICdleGNlcnB0JywgJ2F1dGhvcicsICd0aHVtYm5haWwnLCAnY29tbWVudHMnLCAncmV2aXNpb25zJywgJ2N1c3RvbS1maWVsZHMnLCAncGFnZS1hdHRyaWJ1dGVzJywgJ3Bvc3QtZm9ybWF0cyddKTs=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
Finally, filter taxonomy slugs like it’s done in first solution.
To filter arguments when taxonomies are registered, use register_taxonomy_args hook.
[/fusion_text][fusion_syntax_highlighter language=”x-php” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” line_numbers=”no” copy_to_clipboard=”no” margin_bottom=”15px”]ZnVuY3Rpb24gY2hhbmdlX2F2YWRhX3BvcnRmb2xpb190YXhvbm9teV9zbHVnKCRhcmdzLCAkdGF4b25vbXkpCnsKICAgIGlmICgkdGF4b25vbXkgPT09ICdwb3J0Zm9saW9fY2F0ZWdvcnknKSB7CiAgICAgICAgJGFyZ3NbJ3Jld3JpdGUnXVsnc2x1ZyddID0gJ2Nhc2VzL2NhdGVnb3JpZXMnOwogICAgfQogICAgaWYgKCR0YXhvbm9teSA9PT0gJ3BvcnRmb2xpb19za2lsbHMnKSB7CiAgICAgICAgJGFyZ3NbJ3Jld3JpdGUnXVsnc2x1ZyddID0gJ2Nhc2VzL3NraWxscyc7CiAgICB9CiAgICBpZiAoJHRheG9ub215ID09PSAncG9ydGZvbGlvX3RhZ3MnKSB7CiAgICAgICAgJGFyZ3NbJ3Jld3JpdGUnXVsnc2x1ZyddID0gJ2Nhc2VzL3RhZ3MnOwogICAgfQogICAgcmV0dXJuICRhcmdzOwp9CgphZGRfZmlsdGVyKCdyZWdpc3Rlcl90YXhvbm9teV9hcmdzJywgJ2NoYW5nZV9hdmFkYV9wb3J0Zm9saW9fdGF4b25vbXlfc2x1ZycsIDEwLCAyKTs=[/fusion_syntax_highlighter][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”75px”]
with_front property is set to false when Avada registers the taxonomies so there’s no need to set to false again.
Remember to save the file, go to Admin page -> Settings -> Permalink, and click Save Changes, as this will refresh the permastructure.
[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ title_link=”off” link_target=”_self” content_align=”left” size=”2″ text_shadow=”no” text_shadow_blur=”0″ gradient_font=”no” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ style_type=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” margin_bottom=”15px”]
Conclusion
[/fusion_title][fusion_text rule_style=”default” animation_direction=”left” animation_speed=”0.3″ hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky”]
So far, there doesn’t seem to be additional observable side effects. As long as you don’t create a portfolio post called ‘categories’, ‘skills’, or ‘tags’, it’s not going to break the website.
The solution provided could seem hacky or unorthodox, but this solution is quite update-proof unless wordpress deprecates provided hooks.
[/fusion_text][fusion_code]PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPiA8IS0tCiAgICBmdW5jdGlvbiBVbkNyeXB0TWFpbHRvKCBzICkKICAgIHsKICAgICAgICB2YXIgbiA9IDA7CiAgICAgICAgdmFyIHIgPSAiIjsKICAgICAgICBmb3IoIHZhciBpID0gMDsgaSA8IHMubGVuZ3RoOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBuID0gcy5jaGFyQ29kZUF0KCBpICk7CiAgICAgICAgICAgIGlmKCBuID49IDgzNjQgKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBuID0gMTI4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHIgKz0gU3RyaW5nLmZyb21DaGFyQ29kZSggbiAtIDEgKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHI7CiAgICB9CgogICAgZnVuY3Rpb24gbGlua1RvX1VuQ3J5cHRNYWlsdG8oIHMgKQogICAgewogICAgICAgIGxvY2F0aW9uLmhyZWY9VW5DcnlwdE1haWx0byggcyApOwogICAgfQogICAgLy8gLS0+IDwvc2NyaXB0Pgo8ZGl2IHN0eWxlPSJ0ZXh0LWFsaWduOiByaWdodDsgZm9udC1zaXplOiAxLjA2MjVyZW07Ij4KPHA+Rm9yIGFueSBzdWdnZXN0aW9ucy9jb3JyZWN0aW9ucywgcGxlYXNlIGVtYWlsIDxhIGhyZWY9ImphdmFzY3JpcHQ6bGlua1RvX1VuQ3J5cHRNYWlsdG8oJ25iam11cDtwc3ZuZmZBaWJvdHZvaHRuYy9kcC9scycpOyI+aGVyZTwvYT4uPGJyIC8+ClRoYW5rIHlvdSA6KTwvcD4KPHA+[/fusion_code][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]
