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', 'wpd_endpoint_links' );
add_filter( 'attachment_link', 'wpd_endpoint_links' );
add_filter( 'term_link', 'wpd_endpoint_links' );
add_filter( 'author_link', 'wpd_endpoint_links' );
add_filter( 'post_type_archive_link', 'wpd_endpoint_links' );
add_filter( 'day_link', 'wpd_endpoint_links' );
add_filter( 'month_link', 'wpd_endpoint_links' );
add_filter( 'year_link', 'wpd_endpoint_links' );
Related Posts:
- Put a link to a category round a hard coded A HREF
- How to query for pages/post depending on slug?
- php script to change slug in post automatically
- Custom route and query
- Custom post type permalinks do not appear using the link functions
- Remove slugs from custom posts type
- Allow two posts (from different categories) to have the same slug
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Custom PHP form needs refresh to load page correctly
- Rewrite rule not working, but only when parameter is text
- Weird slug in archives permalink
- How to filter posts by post format “standard” from wp-json api?
- Why is variable not working on custom sql query using wpdb?
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Can’t search posts using WP_QUERY inside AJAX Function
- How can I use wp_query to show all product data using just the products ID?
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Random order of WP_Query results with highest meta value
- Custom page archive query by url var calling page twice on one of my custom queries?
- Global variable $post returning incorrect object
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- get current custom post ID by WP_Query method
- How do you use WP slugs for PDF files / media?
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Using foreach loop breaks
- Create WP_Query to search for posts by their categories or their parent/child categories
- WP Query with custom Shortcode
- wp_query with cat not working
- Add prefix to link url
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- How to use an associative array in post__in with WP_Query?
- If Query In Sidebar
- WordPress plugin for nicer looking slugs? Have multiple pages named the same but they get different slugs
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- What is an equivalent of single_cat_title for getting the slug of the category?
- 200 Rewrite blog post links
- What query string parameter is available for index.php, that works for both pages and blog articles?
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Using WP-API and SSE not authenticating user ID
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- WordPress every page is 404 not found including admin resources
- WordPress returning 404 for multisite pages
- How to use $_GET function WordPress backend
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- WordPress, AJAX and pre_get_posts using conditional tags
- Get users that likes the post
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Exclude posts based on meta value
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Custom query, checking values of multiple meta keys
- My php header() function is not working [closed]
- auto-populating custom nav with all items from custom post type
- inserting a post from an extern php file but post content doesn’t show on wp site
- Create custom permalinks to show Custom Post Type’s relationship?
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WordPress theme options error
- Redirect to another page using contact form 7? [closed]
- Security for data obtained from the database
- Fatal error: Call to a member function query() on a non-object
- Get posts from multiple post type
- Is it possible to retrieve all posts with a certain value for metadata?
- How to get all author posts outside of author templates
- WP_Query fails despite having 1 post
- Create a Blog Template Page
- unable to use ‘new WP_Query’ in AJAX call
- How to get post permalink url without a href
- List taxonomy term slugs within shortcode (do_shortcode)
- wp_query get the 2nd post
- Exclude posts with specific metadata from search?
- How to get post ID in a Page?
- get_template_directory_uri() providing wrong path for img
- Display an image if odd number of posts in grid
- How to retrieve the data from the sever and displaying it in a page?
- How to add div blocks after certain set of post
- How to overwrite orderby with add_query_var
- stripping tags from excerpt in WordPress is not working
- Why doesn’t PhotoSmash plugin play well with wp_query?
- Change product_base programmatically
- get_the_ID() in the footer returns wrong value
- Trouble inputting variable into WP query
- the_posts_pagination() not working in wpquery
- Divi change project category slug
- How to override url params with rewrite rules vars?
- WP_Query: getting posts where custom field exists
- page-slug.php not working but only for specific slug
- How to show meta value code HTML after x paragraph
- Form search query – displaying ACF “Post Object” field as results
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank