New answers tagged

0

Duplicates don't just come from Pages and Posts, WordPress also defines Images and Files from the Media Library as "Posts". This means if you have a file / image in the Media Library with the same name as a page, it will assign the next duplicate a -2 ( from the wp_unique_post_slug() function ) so there's no URL conflicts. TL;DR - Duplicate? Search for ...


5

It is not a bug. As @LuisSanz pointed out, post_type_link isn't used for the built-in post post type. It is used for custom post types only. Skim through get_permalink() function, you will find out that WordPress doesn't use post_type_link filter but uses post_link filter. It means that you're using wrong filter. Then, change post_type_link to post_link ...


0

I think you may be mixing up a couple of concepts here. Use the new template page you made and name it archive-portfolio.php. This will display all portfolio post types in your new template at yoursite.com/portfolio and the url for the portfolio items should take care of itself. They will still be at yoursite.com/portfolio/item1 so no need to change the ...


0

get_post_permalink won't work for draft or pending posts. But there are a couple workarounds you could use. Here there is a similar post with two options.


0

I had this problem. And I checked all forums and trash and drafts and images with the same name. In the end I fond the problem with my incorrect usage of Yoast plugin - the redirect section. I created a redirect for a page which did not exist and that blocked me from creating a page with that url. Once I deleted the redirect I was able to rename the slug.


0

I have discovered the problem. Documentroot in apache has changed, so updating this has fixed the problem


2

I found solution! A Monkeyman Rewrite Analyzur plugin was very helpful: https://wordpress.org/plugins/monkeyman-rewrite-analyzer/ So now, I have such working urls... single.php: /magazine-name/issue-year/issue/article-name archive.php: /magazine-name/issue-year/issue /magazine-name/issue-year /magazine-name On a custom post editor page in wp-admin I ...


0

How about just go to the menu from wp-admin remove product menu(i.e the current one) now create a new menu (Product)using Custom Menu and put url to # and add ur sub menus, if u have different class for current menu u can add custom class too follow these steps In Appearance > Menus, click the Screen Options tab. Under Show advanced menu properties, check ...


0

Personnaly, I prefer use filters to manipulate data before menu generation. Example with wp_setup_nav_menu_item: add_filter('wp_setup_nav_menu_item', function($menu) { $menu->url = ""; return $menu; }); This filter is ran on each retrieved menu item but without nowing which menu is currently processed. Another example with ...


0

If you want to do this with PHP then use a custom walker and targeting the menu directly (if is menu item xxx), but jQuery will do this easily for you using removeAttr $("#menu-item-xxx"). removeAttr("href"); That won't remove the tag, just removes the href="" from the tag.


-1

Try this in your wp-config.php define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); This basically hard-codes the WordPress options for siteurl and home, which will means WordPress will redirect all requests to those URLs. This won't change any permalinks in any content that you have in your site -- to do this I'd recommend ...


7

Extending @Howdy_McGee answer. First you can not have two post with the same slug (Not title) which explained already in other answers. Second you can have page and post with same slug. But you will be able to access only page when your permalink structure is /%postname%/. And there is debate going on this ticket#13459 about this issue/feature since 6 ...


2

Whenever a post is saved WP calls the wp_unique_post_slug function that will compute a unique slug, based on the post title and a suffix like -2 if another post has the same title. However, you can filter this function, to generate your own slug. So, if you want to mess things up, that's possible.


6

As far as I know, you can't have two posts with the same slug. Whenever you attempt to change a post slug to something that already exists, WordPress will append -2 to the newest slug to differentiate the two. So, if you already have a post with the slug of test and attempt to create another post with the same slug, WordPress will instead give that slug test-...


4

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You could get the year from the published $post->post_date... So that when doing the query just use the date argument: $args = array( 'post_type' => $...


3

You can accomplish this with add_rewrite_rule(). I personally like to show this example in a class to make it copy/paste ready. You could throw this in a plugin or functions.php -- some place that loads this code before query_vars, parse_request and init. The goal is to add rewrite rules, make sure you can add custom properties to the main query, then ...


1

Ok, i have some basic ideas. You can install a plugin called Redirection. And after that, you can make like and redirect to some other pages with you own data. but URL will change as the person redirect to the other specific page. Now if you want to them to land on the specific page... you need to make the folder into server directory under the main site ...


0

I think the problem is in the try_files $uri $uri/ /index.php$is_args$args; line. When you're using pretty permalink structure, there's no question mark in $uri so $is_args is useless. But now, /index.php$is_args$args; becomes /index.php$args; which is useless too because there's no question mark and WordPress cannot translate that request into correct ...


0

Searching around and not being able to implement the action through init hook I've found this workaround which for sure isn't the best but does the job nicely. echo "<script type='text/javascript'> window.location=document.location.href; </script>"; at the end of $_POST instructions. If somebody has a better solution, welcome ...


0

It's because your function archive_action is executed when the loop was already made. Try hooking your function into the init action, so it would be executed before the loop. Another prettier approach would be using ajax. So you send the request through Ajax to archive and just use javascript to remove the post from the DOM.


3

If you'd like to keep your slugs for SEO, then you'll want to define a new rewrite tag and leave the default behavior for post slugs. If you'd like a unique id, then instead of looking up possible duplicates, why not just re-use the post ID which is guaranteed to be unique given a MySQL primary index – you can convert it to a base36 number if you want it to ...


0

Agree with the Hugh Man that it is better to check the option before echoing the link, but it is possible to set the static page as a front page and leave the posts page empty. In this case, the link will just point to the home URL. A better approach is to provide a fallback to the posts archive page. Something like this: function slug_all_posts_link() { ...


0

I've actually had a brain fart, and just figured it out.. Since I don't have any single posts, there was no reason to even be rewriting the CPT itself. I simply removed the rewrite line from the CPT and everything is working perfectly.


2

Yes this is correct. You can choose custom permalink the way you want. But it is limited to these official tags only. And %post_id% is one of those tags so you can use it. Just a note here you need to end the custom structure with post ID or name as codex says Make sure to end your structure with either %post_id% or %postname% (e.g. /%year%/%monthnum%...


2

You're using the same slug for both your videos custom post type and video_type taxonomy. Then, when querying post, WordPress don't know what to select from database. Change your videos post type to video or something differs from videos taxonomy slug will solve your problem.


0

You don't have to mess with .htaccess since WordPress has it's own rewrite engine builti in. You are looking for this: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule


1

Additionally, if the CPT has taxonomies associated with it, I've successfully used the following code to rewrite those as well: /** * Set 'with_front' to false for the 'portfolio_category' post taxonomy. */ add_filter( 'register_taxonomy_args', function( $args, $taxonomy ) { if( 'portfolio_category' === $taxonomy && is_array( $args ) )...


1

I found an exact solution I'm looking for. function my_comment_link_filter( $link ) { $link = str_replace( get_permalink() , $custom_permalink , $link ); return $link; }; add_filter( 'get_comment_link', 'my_comment_link_filter' ); It does exactly what I am looking for: It replaces the Page Permalink with the dynamic permalinks when I call the ...


5

Suppose articles is slug of the category. 1. Add a custom rewrite rule: add_action('init', function() { add_rewrite_rule('^articles/([^/]+)/?$', 'index.php?name=$matches[1]', 'top'); }, 10, 0); 2. Filter the post link: add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false) { if ( has_category('articles', $post) ...


0

The issue with your desired structure (and that categories without base are common request but commonly unreliable) is ambiguity. Each rewrite rule is like a tiny program, explaining WP how to turn URL into query variables. It is very important that WP can reliably distinguish which of the rules should handle particular URL. In plain words the usual case ...


0

I created the following, fairly simple function in order to make the pages a higher importance than categories when loading the content. (Note: this may not the best, but a simple way. I found an issue, when using the Advanced Custom Fields plugin, it doesn't insert the custom fields neither of the old, nor of the new page by default. Adding ...



Top 50 recent answers are included