Random post permalink

I built a similar feature for my personal website, that consists of a new database table, WordPress admin page and some .htaccess rewrites. Unfortunately the setup is too involved with my particular installation to be useful as a plugin, but there are plenty of URL shortener plugins available already. A quick search yields this WP … Read more

Add a css class to a taxonomy permalink

The filter you are looking for is term_links-$taxonomy, where $taxonomy is the taxonomy name. This will filter the $term_links links array before outputting by the_terms(): add_filter(‘term_links-cities’, ‘ad_filter_links’); function ad_filter_links($term_links) { foreach ($term_links as $term_link) { $term_link = str_replace(‘<a ‘, ‘<a class=”fancybox”‘, $term_link); } return $term_links; }

How to get this JavaScript working with get_permalink

Probably the best way to do this is as suggested above by using wp_localize_script. You haven’t mentioned how you’re including the javascript – but I’m going to assume you’re doing it the WordPress way. So, something like this: add_action( ‘wp_enqueue_scripts’, ‘wwm_enqueue_scripts’ ); function wwm_enqueue_scripts() { //see the documentation if you don’t understand what’s going on … Read more

Dashes instead of slashes as permalink structure separator

You can replace the dash with something else, preferably not a hyphen, because that would be hard to parse back. In the following example, I use a dot. You have to change two parts: the outgoing permalinks (hook: “{$post_type}_link”) and the request (hook: request) parsing for “incoming permalinks”. The latter is harder, because it is … Read more

Change permalink for a single post entry

Try adding the following to your functions.php: function wpse221475_custom_rewrite_rules() { add_rewrite_rule( ‘^(special-project)?’, ‘index.php?post_type=projects&name=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘wpse221475_custom_rewrite_rules’); Make sure to flush your rewrite rules after adding this rule. Visit: Dashboard -> Settings -> Permalinks Or if you wish, you can use flush_rewrite_rules() programmatically. To redirect requests for http://example.com/projects/special-project to http://example.com/special-project you can parse the … Read more

What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience

Finally after the holidays I returned back to this question. I chose to use Custom Taxonomies instead of Custom Fields. Here is why: It’s faster to make different queries (even if I will not have many posts) Most of these attributes are reusable (shared) They may be changed/modified easily in the future I’m not going … Read more

Date archive permalink modification

You can change the date links by directly modifying the date_structure: function wpd_change_date_structure(){ global $wp_rewrite; $wp_rewrite->date_structure=”news/%year%/%monthnum%/%day%”; } add_action( ‘init’, ‘wpd_change_date_structure’ ); Don’t forget to flush rewrite rules after the change. WordPress will use this to generate the rewrite rules for incoming requests as well as URL output when using API functions like get_year_link, so there’s … Read more

Custom Post Type slug same as page name causing a conflict

What is appearing at http://www.example.org/team-members/ is the ‘post type archive’ for your post type. It’s the automatically generated list of posts created by WordPress. If you don’t want the post type to have an archive you can disable the archive by setting the has_archive argument to false: register_post_type( ‘post_type_name’, array( ‘has_archive’ => false, ) ); … Read more