How do I change attachment slug from name to id

Use the add_attachment hook to update the slug after the attachment has been inserted: function wpse_182454_attachment_id_as_slug( $post_id ) { if ( get_post_field( ‘post_name’, $post_id ) != $post_id ) { wp_update_post( array( ‘ID’ => $post_id, ‘post_name’ => ( string ) $post_id, ) ); } } add_action( ‘add_attachment’, ‘wpse_182454_attachment_id_as_slug’ );

Permalinks: Page Not Found

Do you have mod_rewrite enabled? This sort of thing tends to happen when it’s not. At which point, you only have access to ugly permalinks (?p=N) or “almost pretty” permalinks (/index.php/slug). The latter uses pathinfo to get you the page you’re requesting instead. So I’d suggest double checking whether mod_rewrite is installed and enabled. If … Read more

Permalink Structure CPT With Custom Taxonomy Fails

Setting has_archive to true causes WordPress to generate a rewrite rule for the archive using the rewrite slug, which is not what you want in your case. Instead, explicitly specify the archive slug as a string and the correct rules will be generated: $args = array( ‘has_archive’ => ‘courses’, ‘rewrite’ => array(‘slug’ => ‘courses/%course-type%’,’with_front’ => … Read more

How to Add a Rewrite Rule for Only One Page?

Asumption: You use Apache as your web server. If you already know the page slugs and they won’t change, just add them to your .htaccess file. It’ll be much faster and less complicated. Paste the following Redirect lines at the top of your .htaccess file. Redirect 301 /pagetitle/ /service/pagetitle/ Redirect 301 /pagetitle2/ /another-dir/pagetitle2/ # BEGIN … Read more

WordPress URL redirect

This is quite possible. First off, Making pagename/{customString} resolve as the page itself instead of 404, then, you’re free to decide whether to keep the URI as is and serve the page content, or redirect back somewhere e.g page permalink ( get_the_permalink() ): add_action( “init”, function(){ $pagename = “pagename”; // page slug add_rewrite_rule( sprintf(‘^%s/([^/]*)/?’, $pagename), … Read more