WordPress custom slug (endpoint) and compare all links

All of the API functions that generate links have filters to let you alter the output. Here’s a quick example that covers most of them: function wpd_endpoint_links( $url ){ if( isset( $_COOKIE[‘lang’] ) ){ $url = $url . $_COOKIE[‘lang’] . “https://wordpress.stackexchange.com/”; } return $url; } add_filter( ‘post_link’, ‘wpd_endpoint_links’ ); add_filter( ‘page_link’, ‘wpd_endpoint_links’ ); add_filter( ‘post_type_link’, … Read more

Remove post type slug of all post types from permalinks

function gp_remove_cpt_slug( $post_link, $post ) { if ( ‘race’ === $post->post_type && ‘publish’ === $post->post_status ) { $post_link = str_replace( “https://wordpress.stackexchange.com/” . $post->post_type . “https://wordpress.stackexchange.com/”, “https://wordpress.stackexchange.com/”, $post_link ); } return $post_link; } add_filter( ‘post_type_link’, ‘gp_remove_cpt_slug’, 10, 2 ); At this point, trying to view the link would result in a 404 (Page Not Found) error. … Read more

Wrong generated page_name/slug on first publish of custom post type

When registering or updating any rewrite for any post/custom post type you need to flush rewrite rules by the admin panel or via code: register_activation_hook( __FILE__, ‘plugin_activation’ ); function plugin_activation() { update_option(‘plugin_permalinks_flushed’, 0); } add_action( ‘init’, ‘register_custom_post_type’ ); function register_custom_post_type() { global $wp; register_post_type( ‘review’, array( ‘label’ => ‘Reviews’, ‘labels’ => array( ‘name’ => ‘Reviews’, … Read more

Need to pull parent category and slug – only pulling daughter category

There are functions for retrieving a term/category link (i.e. URL to the term archive page) and in the case of the default category taxonomy, you can use get_category_link(): <a href=”https://wordpress.stackexchange.com/questions/361461/<?php echo esc_url( get_category_link( $category[0] ) ); ?>”><?php echo $category[0]->name; ?></a> For custom taxonomies, you’d use get_term_link().

How to query for pages/post depending on slug?

With a custom Page (post type page) and a custom Page Template, you can do it like so: In the templates, make a new instance of WP_Query which is used for querying the posts in either the Romanian or English language. In the query/function args for WP_Query and wp_get_archives(), use a custom parameter named lang … Read more

Change default search URL slug in wordpress with Custop Post Type as Search target

Hi Vijay you can try to add post_type as query perameter in you redirect url check following changes in your code. function wp_change_search_url() { if ( is_search() && ! empty( $_GET[‘s’] ) ) { get_query_var( ‘post_type’ ); wp_redirect( home_url( “/search/” ) . urlencode( get_query_var( ‘s’ ) ) . ‘?post_type=” . get_query_var( “post_type’ ) ); exit(); … Read more

is_account_page() change to page slug

You could try to use the is_page() function – https://developer.wordpress.org/reference/functions/is_page/ The function signature accepts one parameter – $page (int|string|int[]|string[]) (Optional) Page ID, title, slug, or array of such to check against. Default value: ” if ( is_page(‘account’) ){ // do some code here }

Access files at new location using old file paths

I believe I’ve found the solution. I add the following RewriteRule ^example_directory/files/(.*) new_directory/$1 to my WordPress .htaccess rules like so: RewriteEngine On RewriteBase / RewriteRule ^example_directory/files/(.*) new_directory/$1 RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] I couldn’t get it working before and I think the key was moving the … Read more

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