Hot answers tagged

17

The following code will work, but you just have to keep in mind that conflicts can happen easily if the slug for your custom post type is the same as a page or post's slug... First, we will remove the slug from the permalink: function na_remove_slug( $post_link, $post, $leavename ) { if ( 'events' != $post->post_type || 'publish' != $post->...


8

I tried to figure this out not long ago and the short answer from what I know is no. Not from within the rewrite argument at least. The long explanation becomes apparent if you look at the actual code of register_post_type in wp-includes/post.php line 1454: add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args ); You ...


7

You can use template_include, but before you hook to this filter you must do the following steps: Create page template. e.g: page-target.php <?php /** * Template Name: Page Target */ ... Manually query the contents of target-page on page-target.php template, because the global $post will be referencing to your some-prefix-* page. (Optional): Edit ...


5

I am not sure if this is the best solution or not, but it works: function movie_review_permalink( $url, $post, $leavename ) { $category = get_the_category($post->ID); if ( !empty($category) && $category[0]->slug == "test" ) { //change 'test' to your category slug $date=date_create($post->post_date); $my_date = ...


5

I want ot give you an "alternate" approach. I'm pretty sure you're not going to follow this, but I thinks is interesting to read. OOP "routing" approach In WordPress, "pretty" urls are mathed to "ugly" urls. But most web frameworks (not only PHP) uses the concept of "routing": to match an url to an "action" (or a controller). I want to give you an idea ...


4

It was woocommerce, it has a setting "geolocalize users with cache support" which adds this parameter to every single url and link. I noticed that the hash appended was the same in every browser on my computer, so I realized it wasn't a "session" hash, but an IP address hash.


4

yes, but: it might be hard if drupal mixes several types of content under the /node/ parent. Those are not very SEO or even human freindly URLs so you might actually want to change them and just have a redirect from the old one to the new one.


4

Note that search engines might not like multiple paths to the same content! Here I assume you want e.g.: example.tld/some/path/to/painting-orange example.tld/painting-blue example.tld/painting-red example.tld/painting-yellow to behave like it was this page: example.tld/paintings but not so for paths like: example.tld/painting-white/painting-brown/...


4

The Why Part If we have a page called technical and try to load: example.tld/technical/99999999999999999999 then the 99999999999999999999 part is treated as a page query variable with the value of 2147483647. The reason is this rewrite rule for pages: according to the handy Monkeyman Rewrite Analyzer by Jan Fabry. This part of the WP_Query::...


3

Endpoints are for adding extra query vars to existing routes, I think you just want a vanilla rewrite rule here: function wpd_media_image_rewrite_rule() { add_rewrite_rule( '^image/([^/]*)/?', 'index.php?post_type=attachment&name=$matches[1]', 'top' ); } add_action( 'init', 'wpd_media_image_rewrite_rule' ); You might ...


3

In response to my previous answer: you could of course set the rewrite parameter to false when registering a new post type and handle the rewrite rules yourself like so <?php function wpsx203951_custom_init() { $post_type = 'event'; $args = (object) array( 'public' => true, 'label' => 'Events', 'rewrite' ...


3

I know this topic is old, but I was having the same issue, and none of the suggested fixes worked. I didn't have any pages still in trash. I didn't have a category with the same name as my page. I didn't have another page with the same name. So I did something crazy. WP was trying to name my page as page-2, so I went to mywebsite.com/page to see what ...


3

Yes it is possible, but there isn't much point in that. The crudest way is to use a filter on the result of getting the 'rewrite_rules' option, and manipulating it by adding the entries you require directly to the array, and then you might need to filter those rules out when the option is updated. The thing is that it is most likely a waste of time as as in ...


3

Well, AUTH_KEY and it´s brothers where introduced in WordPress 2.6 to improve safety for logged in users. They are used to encrypt and validate the information in your backend login cookie. While revealing the AUTH_KEY alone might not be a real security issue, you should nevertheless not output/use this anywhere to give less surface for attacks. ...


3

Retrieve "type" of query from url: Previous suggestions As noted in the linked answer, there's url_to_postid(). This will just get you the ID of the object at that endpoint. Long story short, this function will only return an ID and then run a new \WP_Query to get the post type object from the DB and finally return the URl – if there is any and _if it is ...


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 ...


3

Looking at the code, you should be able to filter it. Something like the following should do it: add_filter( 'emoji_url', 'wpse_232874_emoji_cdn_url' ); function wpse_232874_emoji_cdn_url( $url ) { return 'http://example.com/my/cdn/url/'; } ...replacing http://example.com/my/cdn/url/ with whatever URL you want to use. Reference Plugin API


2

I am not sure whether you have hooked this function to appropriate action. Also you have not concatenated the strings properly: Instead of $newdestinationurl = $url/$destinationurlslug ; it should be $newdestinationurl = $url."/".$destinationurlslug ; Please see below for the complete code: function ninja_forms_handler() { add_action ( '...


2

Caveat: the code examples within this answer are very basic and may or may not need further conditional logic to adapt to your precise needs, this logic is meant as an example to get you on your way. There's two considerations you need to be aware of: Consideration 1: If you add a new post and save it with a post_status of draft first, the post will not ...


2

WordPress tries to guess what post the user want to see by post name. That is what is making both example.com/new-bikes/ktm/duke/ktm-690-duke-2012/ and example.com/new-bikes/ktm/yamaha/ktm-690-duke-2012/ return the same and "correct" content. What is important is that, if you see at the source code of example.com/new-bikes/ktm/yamaha/ktm-690-duke-2012/, you ...


2

You can explode URL by ? and take the first part: $url = explode( '?', esc_url_raw( add_query_arg( array() ) ) ); $no_query_args = $url[0];


2

I'd put an is_user_logged_in conditional into my theme's 404.php. Then for logged in users show a form with the new slug as a hidden or uneditable field that creates a new page and redirects to the admin edit screen for that page.


1

Try the fourth input parameter (available in 4.2+): @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'. So change your code snippet to: $new_image_url = media_sideload_image($new_url, $post_ID, $title, $src = 'src' ); to get the src instead of the default html. Note that the output might also be an ...


1

....if you are planning to have many entries (say - over 100), you will run into memory issue Any hierarchical post type (even the build-in post type page) have this issue where a large amount of posts created have a huge impact on performance. This issue is experienced in the back end, and not in the front end. Having too much posts can lead to your back ...


1

OK, here's what I got working in the end. I'm honestly not sure if I've sanitised the parameters correctly so input welcome there! Other than that, all works as intended. Big thanks to Pieter Goosen! // action add_action('pre_get_posts', 'my_pre_get_posts', 10, 1); function my_pre_get_posts( $query ) { // bail early if is in admin if( is_admin() ) ...


1

You need to build a proper meta_query. Your code will only work when you have one meta_key set, if you have more than 1, everything will be haywire. Also note, you should never ever use any unsanitized, non validated values from a $_GET variable (and for that matter any value coming from anywhere). It is extremely easy to inject malicious code into your ...


1

You would want to filter the category link to add the custom variable to the category link. You can make use of the get_term_link filter to filter the category link address Here is a very basic idea: Suppose that we, taken from OP, that you need to add the custom variable only to terms belonging to the build in taxonomy category, and only when we are on a ...


1

@Pat Gilmour is on the right track. The source to handle this is here. First thing you want to do is open the wp-config.phpfile in your SFTP (secure FTP). Add these two lines to your wp-config.php, where "example.com" is the correct location of your site. define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); Read that ...


1

The best way to fix this is to install PHPmyAdmin and then navigate to the wp-options table and change the site-address row. To install PHPmyAdmin, click on "Browse Marketplace" and search for PHPmyAdmin.



Only top voted, non community-wiki answers of a minimum length are eligible