How to generate slugs?

As @toscho already answered here, yes this is possible. You just need to copy this code into the functions.php of your theme, and there you go. // get all posts $posts = get_posts( array ( ‘numberposts’ => -1 ) ); foreach ( $posts as $post ) { // check the slug and run an update … Read more

How to remove certain words from url slug

There should be no problem with unset. There is your answer. What matters with a filter is what you return and unseting those keys before your rebuild the string and return it, works. You are doing too much processing by explodeing your $keys_false inside a loop, and you have a typo, and you are better … Read more

How to prevent duplicate slugs for wp_insert_post?

If you use wp_insert_post, it should calculate a unique post slug for you. If you don’t use wp_insert_post, try using wp_unique_post_slug. If neither of those are working for you, you could simple try appending -page or to the new page’s post_name (slug) before inserting it. WordPress does its uniqueness check on post slugs at application … Read more

Add warning to edit slug/permalink button on editor screen.

WordPress has already hooked jQuery events to that button which you could omit with off() method, or keep things simple and add an overlay above that button and act as the button, prompting users to confirm the editing action at first place: jQuery(document).ready(function($){ var c = $(‘#edit-slug-buttons’) , b = $(‘button’,c).first(); c.css({ position: ‘relative’ }).append(‘<span … Read more

Remove Slug from Custom Post Type

There is a simpler and lighter solution: First: set the slug argument for your custom post type to “https://wordpress.stackexchange.com/” when registering the post type: add_action( ‘init’, ‘register_my_post_type’ ); function register_my_post_type() { $args = array( //The rest of arguments you are currently using goes here ‘rewrite’ => array( ‘slug’ => “https://wordpress.stackexchange.com/” ) ); register_post_type( ‘my-post-type’, $args … Read more

Force post slug to be auto generated from title on save

The easiest workaround could be: function myplugin_update_slug( $data, $postarr ) { if ( ! in_array( $data[‘post_status’], array( ‘draft’, ‘pending’, ‘auto-draft’ ) ) ) { $data[‘post_name’] = sanitize_title( $data[‘post_title’] ); } return $data; } add_filter( ‘wp_insert_post_data’, ‘myplugin_update_slug’, 99, 2 );

Can I use a number for a post/page slug?

It’s only Pages where this is an issue. Posts are fine. Seems like a bug to me, but regardless of whether or not it’s a bug, you can not use numeric slugs on pages. This is because number slugs like “/750/” interfere with posts years “/2010/” etc. and WordPress can’t tell the difference. If you … Read more

How to check if a slug exists?

This is what you’re looking for, tested and I use it on my own sites: function the_slug_exists($post_name) { global $wpdb; if($wpdb->get_row(“SELECT post_name FROM wp_posts WHERE post_name=”” . $post_name . “””, ‘ARRAY_A’)) { return true; } else { return false; } } You can then use it like this: if (the_slug_exists(‘contact’)) { // do something } … Read more

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