Redirect old permalinks to new permalinks

WordPress should handle the 301 redirects for you automatically in this case. It doesn’t always, but it should here. Long story short, WordPress has a function, redirect_guess_404_permalink which tries to find the correct post when it encounters a 404 by using the end of the 404 url to query against the wp_posts.post_name. If it finds … Read more

How to i18n slugs for templates?

Filter template_include: add_filter( ‘template_include’, ‘prefix_translate_template’ ); function prefix_translate_template( $template ) { if ( ‘category-‘ . __( ‘news’, ‘your_textdomain’ ) . ‘.php’ === $template ) return ‘category-news.php’; return $template; } But I think templates based on slugs are not a good idea in that case.

Subdomains to pages

It’s better to use WP_Rewrite for that. add_action(‘page_rewrite_rules’,’my_page_rules’); function my_page_rules($rules){ $pageslug = ‘sample-page’; $rules[‘([^/]+)/?$’] = ‘index.php?pagename=”$pageslug”/$matches[1]’; return $rules; } add_filter( ‘page_link’, ‘sub_page_link’); function sub_page_link(){ // preg_replace here } I have found a premium plugin which uses the same mechanism to convert pages into subdomain, it uses rewrite rules and Server WildCard Configured. Hope it is … Read more

WP JSON list all permalinks

Is it possible to do this with a rest query + filters? eg. http://wpsite.com/wp-json/wp/v2/posts?filter[only-permalinks] Yes, since 4.9.8 (see #43874) it’s possible to render only fields needed with the _fields parameter. Examples Render only the permalinks: https://example.com/wp-json/wp/v2/posts?_fields=link [ { link: “https://example.com/foo/” }, { link: “https://example.com/bar/” }, ] Render only the post IDs and permalinks: https://example.com/wp-json/wp/v2/posts?_fields=id,link [ … Read more

mod_rewrite enabled but Permalinks show index.php

The output of $_SERVER[‘SERVER_SOFTWARE’] is WebServerX That looks like your problem – check out this line in wp-includes/vars.php: /** * Whether the server software is Apache or something else * @global bool $is_apache */ $is_apache = (strpos($_SERVER[‘SERVER_SOFTWARE’], ‘Apache’) !== false || strpos($_SERVER[‘SERVER_SOFTWARE’], ‘LiteSpeed’) !== false); I think you’ll need to override this variable manually, either … Read more

Custom Post Type: Get most recent permalink

Here is a simple function that will return the Permalink of the last painting post: function Get_most_recent_permalink(){ global $post; $tmp_post = $post; $args = array( ‘numberposts’ => 1, ‘offset’ => 0, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘Painting’, ‘post_status’ => ‘publish’ ); $myposts = get_posts( $args ); $permalink = get_permalink($myposts[0]->ID); $post = $tmp_post; … Read more

What is the best practice to check for pretty permalinks?

The Using Permalinks page on WordPress.org tells you how to check for the permalink structure: if ( get_option(‘permalink_structure’) ) { echo ‘permalinks enabled’; } The result will be an empty string if permalinks are default, otherwise you will get the permalink pattern though you should not have to worry much about the permalink details if … Read more

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