Rename Custom Post Slug using taxonomy

You’re passing 3 arguments to your function ($permalink, $post, $leavename), but you’re only specifying that it has 2 when you’re adding the filter (the last parameter to add_filter). Change your add_filter call to this: add_filter( ‘post_type_link’, ‘custom_post_type_link’, 10, 3 );

Problem with get_permalink, to get page content

The answer lies in your question already… When you use get_permalink for your post 171, it gets you https://mysite/2018/11/24/152-revision-v1 So, as you can see, this post is not a published post, but a revision of a post. Revisions are not public, so you can’t see them… So how to solve that? You’ll have to check … Read more

Disable “similar permalink” redirect [duplicate]

To completely disable this feature, use this code, which I got from here. remove_action( ‘template_redirect’, ‘redirect_canonical’ ); To only disable it for URL addresses that contain the string ‘event’, use this code: add_filter( ‘redirect_canonical’, ‘disable_redirect_canonical_for_event’, 2, 10 ); function disable_redirect_canonical_for_event( $redirect_url, $requested_url ) { if ( strpos( $requested_url, ‘event’ ) !== false ) { return … Read more

In a multisite, how can I get posts from one site and display their permalinks in another site?

Let’s take a look at get_blog_permalink: get_blog_permalink( $blog_id, $post_id ) { switch_to_blog( $blog_id ); $link = get_permalink( $post_id ); restore_current_blog(); return $link; } As you can see, there’s no magic… But there are some problems, since switch_to_blog isn’t very efficient… It means that it would be way better if you’d done it this way: $tp_blog_id … Read more

WordPress plugin how to run function when button is clicked

Create form or link with action=”my_media_update” <form action=”<?php echo admin_url(‘admin-post.php’); ?>” method=”post”> <input type=”hidden” name=”action” value=”my_media_update”> <input type=”submit” value=”Update Media Titles and ALT Text”> </form> Add this function and hook in your plugin file: public function kh_update_media_seo() { //update media files title and alt tags here // // at the end redirect to target page … Read more