Tagged: enfold
-
AuthorPosts
-
January 7, 2021 at 10:48 pm #1270959
To remove “portfolio-item” from the URL, should I just remove it from the “Portfolio Items Base” on the Permalinks Settings page?
Then, should we use “Post Name” for the Common Settings?
https://visualimpactsystems.com/WJCA-PermalinksPage-7JAN21.png
Thank you for your time and effort,
Mark Besh
Visual Impact SystemsJanuary 10, 2021 at 4:01 am #1271271Hi Mark,
You can’t remove it altogether unfortunately, since it’s a custom post type. You can change it to something different on the page in your screenshot though.
Best regards,
RikardJanuary 10, 2021 at 9:55 pm #1271393Rikard,
Hmmm… Y’all helped us remove them from our company site we did with Angular in 2013:
https://visualimpactsystems.com/
(I think you had us put something in a .php file?)Mark Besh
Visual Impact SystemsJanuary 12, 2021 at 1:53 pm #1271896Hi!
Thank you for the update.
Y’all helped us remove them from our company site
You might be referring to this snippet or filter, which modifies the post link.
// https://kriesi.at/support/topic/masonry-gallery-order-and-sizing/#post-741588
UPDATE: We tested the filter but for some reason it is no longer working as expected. It does remove the base slug, but the portfolio item returns a 404 error page. We will let you know once we have found the issue.
The solution from this article might help.
// https://kellenmace.com/remove-custom-post-type-slug-from-permalinks/
Regards,
IsmaelJanuary 25, 2021 at 2:21 pm #1275268Ismael,
Hmmm… It doesn’t seem to be working:
I added it to the bottom of the “functions.php” file:
. . . . . ./*
* register custom functions that are not related to the framework but necessary for the theme to run
*/require_once( ‘functions-enfold.php’);
add_filter( ‘post_type_link’, ‘ava_remove_custom_slug’, 9999, 3 );
function ava_remove_custom_slug( $post_link, $post, $leavename ) {
if ( ‘portfolio’ != $post->post_type || ‘publish’ != $post->post_status ) {
return $post_link;
}$post_link = str_replace( ‘/’ . $post->post_type . ‘/’, ‘/’, $post_link );
return $post_link;
}Any idea why it’s not working?
[ Question: I noticed there is a “functions-enfold.php” Should I have put it in there? ]Thanks for your help on this.
Mark Besh
Visual Impact SystemsJanuary 26, 2021 at 8:26 am #1275415Hi,
Did you also try to add the pre_get_posts filter from the kellenmace article above?
You may need to flush the permalink setting and remove the value of the Portfolio Base Slug field in the Settings > Permalinks panel. To flush the permalinks, just go to the permalinks panel, then hit save or update. Do this after adding the modifications above.
Best regards,
IsmaelJanuary 27, 2021 at 4:32 pm #1275824Ismael,
So, do you want me to ADD the following code to what I already have? (or instead of?)
<?php
/**
* Remove the slug from published post permalinks. Only affect our custom post type, though.
*/
function gp_remove_cpt_slug( $post_link, $post ) {if ( ‘race’ === $post->post_type && ‘publish’ === $post->post_status ) {
$post_link = str_replace( ‘/’ . $post->post_type . ‘/’, ‘/’, $post_link );
}return $post_link;
}
add_filter( ‘post_type_link’, ‘gp_remove_cpt_slug’, 10, 2 );If you want me to ADD it, where do you want me to add it? Before or after?
Mark Besh
Visual Impact SystemsJanuary 28, 2021 at 5:56 am #1275954Hi,
You have to add the pre_get_posts filter along with the previous code that we recommended and remove the slug and set the with_front parameter of the portfolio post type to false. The pre_get_posts function should alter the default query.
This is the final code, which seems to be working properly when we tested it on our installation.
/** * Remove the slug from published portfolio permalinks. Only affect our custom post type, though. */ function avf_portfolio_cpt_args_mod($args) { $args['rewrite']['slug'] = '/'; $args['rewrite']['with_front'] = false; return $args; } add_filter('avf_portfolio_cpt_args', 'avf_portfolio_cpt_args_mod', 10); function ava_remove_custom_slug( $post_link, $post, $leavename ) { if ( 'portfolio' != $post->post_type || 'publish' != $post->post_status ) { return $post_link; } $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } add_filter( 'post_type_link', 'ava_remove_custom_slug', 9999, 3 ); /** * Have WordPress match postname to any of our public post types (post, page, portfolio). * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts. * By default, WordPress only accounts for posts and pages where the slug is /post-name/. * * @param $query The current query. */ function ava_add_cpt_post_names_to_main_query( $query ) { // Bail if this is not the main query. if ( ! $query->is_main_query() ) { return; } // Bail if this query doesn't match our very specific rewrite rule. if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) { return; } // Bail if we're not querying based on the post name. if ( empty( $query->query['name'] ) ) { return; } // Add CPT to the list of post types WP will include when it queries based on the post name. $query->set( 'post_type', array( 'post', 'page', 'portfolio' ) ); } add_action( 'pre_get_posts', 'ava_add_cpt_post_names_to_main_query' );
Please do not forget to flush or save the permalink settings.
Best regards,
IsmaelJanuary 28, 2021 at 2:06 pm #1276051Ishmael,
Hmmm… So, to the original functions.php (v4.7.6.3), I added your all of your code at the bottom of the functions.php file (Meaning I DID NOT put the code in from the January 25, 2021 at 2:21 pm post).
Before overwriting the old functions.php with the new one with your code, I flushed the GoDaddy cache, then I flushed the Permalinks by clicking on “Save Changes” in the Permalinks Setting (which gave me this notice: “Permalink structure updated.”). [ I tried both remove the “portfolio-item” then saving and leaving it in there and saving—no difference ].
Then I did the “Visit Site” from the Dashboard and it gave me this message: “There has been a critical error on this website. Learn more about debugging in WordPress.” (It ‘froze’ the site and Dashboard was it was no longer working). [ However, I was doing all this via CyberDuck, so I just replaced it with the original functions.php and everything was fine [.
[ Note: I did put a “closing bracket” ( “}” ) in an additional line at the bottom and it still broke the site. ]
Can you tell me what I am doing wrong?
Thanks for ALL your help on this!
Mark Besh
Visual Impact SystemsJanuary 29, 2021 at 5:05 am #1276226Hi,
You have to remove the previous snippet that we provided and use the recent one above because that is the complete code. After adding the code, make sure that the Portfolio Item Slug is set to a slash (“/”) and make sure to flush or save the permalink settings. After that, refresh the page, go to the Portfolio panel, and view one of the portfolio items. The post type slug should be removed from the URL.
Would you mind if we access the dashboard and the file server? Please post the WP and FTP login details in the private field so that we could test the modification.
Thank you for your patience.
Best regards,
IsmaelJanuary 29, 2021 at 1:40 pm #1276293Ismael,
We did exactly what you told us to, and it still gives the critical error.
Thank you for offering to help us. The login info for the Staging site is below in the private area.
Mark Besh
Visual Impact SystemsJanuary 29, 2021 at 2:44 pm #1276307Hi,
Thank you for the info.
The code that we recommended above is nowhere to be found in the functions.php file, so we added it. You may need to use a child theme in order to preserve this modification. (see private field)
Best regards,
IsmaelJanuary 29, 2021 at 3:54 pm #1276335Ismael,
Yes, as I mentioned, when I put your code in it ‘broke’ the site, and Dashboard was not available (That’s why I mentioned I was using Cyberduck to copy the functions.php file into the Enfold directory).
Yes, it looks like it is working properly. THANK YOU VERY MUCH! (I’m going to have to compare your functions.php with mine to see what the difference was—or maybe it was the ‘process’ you used to do it).
I have copied the functions.php file, and yes, know we will have to put your code into it when we update the theme.
SO, just to be clear, so we can put the proper code into the next functions.php file (after a theme update), it looks like you ‘redid’ this code that was at the end of the original functions.php:
add_filter( ‘post_type_link’, ‘ava_remove_custom_slug’, 9999, 3 );
function ava_remove_custom_slug( $post_link, $post, $leavename ) {
if ( ‘portfolio’ != $post->post_type || ‘publish’ != $post->post_status ) {
return $post_link;
}$post_link = str_replace( ‘/’ . $post->post_type . ‘/’, ‘/’, $post_link );
return $post_link;
}which came just after this:
/*
* register custom functions that are not related to the framework but necessary for the theme to run
*/require_once( ‘functions-enfold.php’);
SO, should I just add all of this code after that “require_once” code in any future functions.php file after a theme update?:
/**
* Remove the slug from published portfolio permalinks. Only affect our custom post type, though.
*/
function avf_portfolio_cpt_args_mod($args) {
$args[‘rewrite’][‘slug’] = ‘/’;
$args[‘rewrite’][‘with_front’] = false;
return $args;
}
add_filter(‘avf_portfolio_cpt_args’, ‘avf_portfolio_cpt_args_mod’, 10);function ava_remove_custom_slug( $post_link, $post, $leavename ) {
if ( ‘portfolio’ != $post->post_type || ‘publish’ != $post->post_status ) {
return $post_link;
}$post_link = str_replace( ‘/’ . $post->post_type . ‘/’, ‘/’, $post_link );
return $post_link;
}
add_filter( ‘post_type_link’, ‘ava_remove_custom_slug’, 9999, 3 );/**
* Have WordPress match postname to any of our public post types (post, page, portfolio).
* All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
* By default, WordPress only accounts for posts and pages where the slug is /post-name/.
*
* @param $query The current query.
*/
function ava_add_cpt_post_names_to_main_query( $query ) {// Bail if this is not the main query.
if ( ! $query->is_main_query() ) {
return;
}// Bail if this query doesn’t match our very specific rewrite rule.
if ( ! isset( $query->query[‘page’] ) || 2 !== count( $query->query ) ) {
return;
}// Bail if we’re not querying based on the post name.
if ( empty( $query->query[‘name’] ) ) {
return;
}// Add CPT to the list of post types WP will include when it queries based on the post name.
$query->set( ‘post_type’, array( ‘post’, ‘page’, ‘portfolio’ ) );
}
add_action( ‘pre_get_posts’, ‘ava_add_cpt_post_names_to_main_query’ );Ismael, thank you for ALL your effort on this!
Mark Besh
Visual Impact SystemsFebruary 1, 2021 at 4:32 am #1276673Hi,
You are very welcome! Glad we could help.
Yes, we removed the previous ava_remove_custom_slug and added it again along with the ava_add_cpt_post_names_to_main_query and avf_portfolio_cpt_args_mod functions. To avoid further confusion, you can copy the final code here.
// https://kriesi.at/support/topic/enfold-remove-portfolio-item-from-the-url/#post-1275954
Thank you for your patience.
Best regards,
IsmaelFebruary 3, 2021 at 11:04 pm #1277476Ismael,
Don’t know if this new issue is related to the code addition, but it might be, so I thought I would tell you about the new issue here (you could move it to another ‘thread’ if it is not associated with the removal of the portfolio-item permalink).
It’s pretty simple: We have developed this new site for this client in the “Staging” area on GoDaddy. We just ‘pushed’ the site to “Live” (and clicked on “Overwrite”), and none of the icons are showing up [ Magnifying glass for search (in menu and footer on “Home” page); Icons in blue circles (on “About” page); book icons in the blue circles (on the “Resources” page) ]. (I think that is all that is missing).
“Staging” Site (everything seems to work just fine):
“Live” Site (missing icons):
Is this related to the removal of the permalinks? (and/or related to the icon font?)
If this is not ‘transferring’ properly, could there be other things in the future that might not go from Staging to Live using Enfold with GoDaddy?
Thanks for your help,
Mark Besh
Visual Impact SystemsFebruary 5, 2021 at 7:33 am #1277862Hi Mark,
The icon font is being blocked by the browser on the live site, since it’s being served from a CDN, please see private. Please try reaching out to your hosting provider, and ask them for headers which would allow the font file to be loaded by the browser.
Best regards,
RikardFebruary 5, 2021 at 1:30 pm #1277982Rikard,
We are planning to install WP-Rocket on the Live site (when we are finished with development). Do you know if it has, in its configuration area, the ability to do what you are suggesting, or is this a ‘core’ server kind of thing?
[ OR, would you suggest turning off the CDN that GoDaddy provides and only use WP-Rocket? ]
Thanks for your help.
Mark Besh
Visual Impact SystemsFebruary 6, 2021 at 1:16 pm #1278239Hi Mark,
I don’t think WP Rocket has an option for that, since the headers for that would likely be server specific. CDN services are good in general in my experience, so turning it off completely would likely not be a good idea. Please try reaching out to GoDaddy, to see if they can help you out with the appropriate headers, so that the icon font is allowed to be loaded by the browser.
Best regards,
RikardFebruary 15, 2021 at 3:44 pm #1280570Rikard,
Just to help anyone that hosts the Enfold theme on GoDaddy, here’s the code that they had me put into the .htaccess file to ‘unblock’ loading the Enfold icon font:
<IfModule mod_headers.c>
<FilesMatch “\.(ttf|ttc|otf|eot|woff|woff2|css|js)$”>
Header set Access-Control-Allow-Origin “*”
</FilesMatch>
</IfModule>[ NOTE: There is also this code to put into the .haccess file to work with GoDaddy’s Sucuri firewall and their CDN (Be sure to disable the Managed WordPress CDN in the “Production” settings):
# BEGIN Website Firewall Bypass Prevention
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?DOMAIN_HERE.com$
RewriteCond %{HTTP:X-SUCURI-CLIENTIP} ^$
RewriteCond %{HTTP:X-SUCURI-COUNTRY} ^$
RewriteRule ^(.*)$ – [F,L]
ErrorDocument 403 Forbidden
# END Website Firewall Bypass PreventionThis was the first ‘item’ in the .htaccess file. (Put the URL of the site in the “DOMAIN_HERE”) ].
Thank you VERY MUCH for all your/everyone’s efforts on this!
Issue solved.
Mark Besh
Visual Impact SystemsFebruary 16, 2021 at 1:58 pm #1281327 -
AuthorPosts
- The topic ‘Enfold – Remove "portfolio-item" from the URL’ is closed to new replies.