Allow dot in wordpress permalinks (only for categories)

Well in case you need to change look of generated permalinks take a look to sanitize_title_with_dashes function which is one of filters of the sanitize_title hook filters. If that only one request for this filter (avoid replacing .) you can copy/paste this function with a same name and remove original reference and add new. remove_filter(‘sanitize_title’, … Read more

Custom fields in Permalinks?

Use add_rewrite_tag( $tag, $regex ); to register a rewrite tag for the custom field. Filter post_type_link to replace the rewrite tag. The second argument is the post object, so you have always access to the post ID. For a sample implementation see my plugin T5 Rewrite. It does exactly that in the class T5_Rewrite_Tag_Custom.

How to set up Author archives with sub category URL

As I mentioned in my comment, you can use add_rewrite_endpoint to accomplish this. First, add the endpoint: function wpa_author_endpoints(){ add_rewrite_endpoint( ‘liked-posts’, EP_AUTHORS ); } add_action( ‘init’, ‘wpa_author_endpoints’ ); After flushing rewrite rules (visit your Settings > Permalinks page in admin), author URLs can now be appended with /liked-posts/. Next, add a filter to author_template to … Read more

Best way to add internal link in widget

The page ID can vary in different installation, and it can’t be changed, so an option is to use get_page_by_path because the page slug can be easily changed: <div class=”my-link-box”> <?php $page = get_page_by_path(‘my-page’); ?> <a href=”https://wordpress.stackexchange.com/questions/126876/<?php echo get_permalink($page); ?>”><?php echo $page->post_title; ?></a> </div> However this is not a great solution as well. Once you … Read more

Get canonical link

Since WP 4.6 there has been a core function for this: wp_get_canonical_url() Call it with a post ID to get that post’s canonical URL, or in the loop without a post ID to get the current post’s canonical URL.

How to tranform Headlines into linkable permalinks?

Analysed situation When you take a look at your (original) example “GitHub” and it’s source code, you see the following: <a name=”updating-submodules” class=”anchor” href=”#updating-submodules”> <span class=”octicon octicon-link”></span> </a> Prerequisites Basically this is possible (even pretty easy), but you’ll have to have theme templates that properly use WordPress Templates Tags. The functions that are needed are … Read more

Different permalink for CPT and regular Posts/Pages but why?

The permalink configuration in WordPress backend is only for standard posts and pages. For CPT the default URL structure is http://example.com/cpt-identifier/post-slug. If you want a different URL structure for you CPT you will have to define and register your own rewrite rules. For example: add_action( ‘init’, ‘register_posttype’ ); function register_posttype() { register_post_type( ‘my_cpt’, //this will … Read more

Link to external URL

Without http:// in front, your code won’t work. You will need to add that infront. You can make use of parse_url to add http:// to urls that does not have that. To make this protocol agnostic, you can simply use // You can try something like this $urlStr=”www.google.com”; $parsed = parse_url($urlStr); if ( empty( $parsed[‘scheme’] … Read more

Should there be a trailing slash in the permalink

It makes no difference performance-wise, if it did, there’d be something seriously wrong with WordPress. The same goes for Google, if a lot of super smart people earning 100k salaries can’t write software that handles a trailing slash, then something is terribly wrong with the world. Either way, WordPress puts the rel=”canonical” tag in the … Read more