Use custom template on certain URLs

Thanks to @Milo on the comments, I’m gonna post my answer: Firstly I added this rule: add_rewrite_rule( “en/artist/([^/]+)/?”, ‘index.php?pagename=post_type=artist&artist=$matches[1]&gal_template=en’, “top”); Then this filter: add_filter( ‘query_vars’, ‘gal_query_vars’ ); function gal_query_vars( $query_vars ) { $query_vars[] = ‘gal_template’; return $query_vars; } Finally, I filtered the single template: add_filter( ‘single_template’, ‘get_custom_post_type_template’ ); function get_custom_post_type_template($single_template) { global $post; if ($post->post_type … Read more

Cleanup URL for a custom page in wordpress

You can do this with the internal rewrite system, which is parsed in php, not htaccess. First, add the rule. This assumes you have created a root page under Pages with the slug dictionary. function wpd_dictionary_rewrite(){ add_rewrite_tag( ‘%dictionary_word%’, ‘([^/]+)’ ); add_rewrite_rule( ‘^dictionary/([^/]+)/?$’, ‘index.php?pagename=dictionary&dictionary_word=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘wpd_dictionary_rewrite’ ); This code would go in … Read more

Rewrite rule to load images from production does nothing

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] # If images not found on development site, load from production RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$ RewriteRule ^(.*)$ https://www.example.com/$1 [QSA,L] The problem here is that “If images not found on development site” then the request has already been rewritten to index.php by the preceding RewriteRule (WordPress front-controller), … Read more

Remap URLs from Relative to Absolute

WP CLI is a great tool for performing common admin and maintenance tasks on a WordPress install. It has a large range of commands that among other things allow you to install plugins, regenerate thumbnails, and in your case, perform a search and replace on the database. When migrating from dev to production I’d normally … Read more

Nginx rewrite rules

The correct Nginx rewrite rules for WordPress are: location / { try_files $uri $uri/ /index.php?q=$uri&$args; } This sends everything through index.php and keeps the appended query string intact. If your running PHP-FPM you should also add this before your fastcgi_params as a security measure: location ~ \.php { try_files $uri =404; // fastcgi_param …. // … Read more

open all .docs in word online

I’m not sure this question is WordPress-related. It sounds like it might be handled via .htaccess redirect, or a browser extension. That said: you could try to use the wp_get_attachment_url filter, that is applied to the URL returned by wp_get_attachment_url(). For example: function wpse95271_filter_wp_get_attachment_url( $url ) { if ( 0 === stripos( strrev( $url ), … Read more

How to properly rewrite url by custom var

So, first off, never flush rewrite rules on every page load. Better to do it on plugin activation one time. Step 1: add the rewrite rule: add_action( ‘init’, ‘wpse26555_add_rewrite’ ); function wpse26555_add_rewrite() { // You should probably rewrite to index.php instead of shop.php? add_rewrite_rule( ‘/shop/brand/([^/]+)/?$’, ‘index.php?brand=$matches[1]’, ‘top’ ); } Step 2: add the query var … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)