Tag Info

Hot answers tagged

17

You are almost there. The function you need is sanitize_title_with_dashes( $title )


15

use global variable $post. <?php global $post; $post_slug=$post->post_name; ?>


12

You seem to need "partial verbose rewrite rules". Verbose rewrite rules means all the pages are put on top because WordPress can't figure out the difference between a page and a post. Here it thinks it can, because all URLs of the form portfolio/([^/]+)/ are from your portfolio taxonomy, except this one portfolio/clients/. You will have to put that one on ...


11

The function you are looking for is get_term_by. You would use it as such: <?php $term = get_term_by('slug', 'my-term-slug', 'category'); $name = $term->name; ?> This results in $term being an object containing the following: term_id name slug term_group term_taxonomy_id taxonomy description parent count The codex does a great job explaining ...


11

The following 2 filters allow you to hook into when WordPress checks the slug and are found in the function wp_unique_post_slug() in the wp-includes/post.php file. There are 2 filters, one for hierarchical posts and one for non-hierarchical. The hierarchical filter provides the ID for the post parent so if the $post_parent is 0, you know this is a "base" ...


10

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 );


9

I wouldn't try to localize your slugs. Instead, why not give your users the option to change them by adding another field to the permalink settings page? Hook into load-options-permalink.php and set up some things to catch the $_POST data to save your slug. Also add a settings field to the page. <?php add_action( 'load-options-permalink.php', ...


8

Use get_posts() and the parameter name which is the slug: $page = get_posts( array( 'name' => 'your-slug' ) ); if ( $page ) { echo $page[0]->post_content; } Be aware that the post type in get_posts() defaults to 'post'. If you want a page use … $page = get_posts( array( 'name' => 'your-slug', 'post_type' => ...


7

The string used in WordPress to identify the plugin is: plugin_basename($file); … where $file is a file with the plugin headers. So if you are in your plugin, get the slug with: $slug = plugin_basename( __FILE__ );


7

You'll want to hook in to the wp_handle_upload_prefilter filter (which I can't find any documentation on, but seems pretty simple). I've tried this out locally, and it seems to work for me: function wpsx_5505_modify_uploaded_file_names($arr) { // Get the parent post ID, if there is one if( isset($_REQUEST['post_id']) ) { $post_id = ...


7

I see two ways to solve this problem: changing the data that forms the author URL, or changing the author URL. You probably should handle redirects too, so old URLs to user archives keep working when a user changes their nickname. Changing the author URL There are two parts to this question: handle incoming links with the author nickname instead of the ...


7

Due to wp_posts table structure the length of post_name column (the column for slugs) is equal to 200 characters.


7

For some sites in German I use the following plugin to translate page to seite (the German word for page): <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Page to Seite * Description: Ersetzt <code>/page/</code> durch <code>/seite/</code>. * Author: Thomas Scholz <info@toscho.de> * Author URI: http://toscho.de ...


6

Permalinks like http://example/שָׁלוֹם are actually working in my WordPress 3.3. Could be the remove_accents() improvements for i18n permalinks. As Sean & Steve noted, make sure you're using WordPress ≥ 3.3 make sure your .htaccess file contains a rule similar to RewriteRule . /index.php [L] check that your database is UTF-8 encoded (and consider ...


6

Providing you know what you're doing that shouldn't be a problem. You will however have to check that any author/user pages you may have are linked by id rather than name in the code: $data = get_userdata( $userid ); As opposed to $data = get_userdata('Admin'); Because the ID will never change (unless you delete the row and re-insert) but if you ...


6

You can use get_permalink() outside of the loop, that should do what you need.


6

I figured out a solution and decided I'd share because its nice to be nice. This works for me and is based on a solution by Jonathan Brinley. If anyone has any suggestions or corrections please feel free to let me know. First, create your custom post type and set it up like this (this is just an example, remember to make it fit your own needs. The slug ...


6

Hi @NetConstructor: Well if I had thought about how much work with was going to be before writing it, you wouldn't be able to get me points right now. :) Needless to say, it's rather involved (though I don't think it really should have to be, but it is what it is.) First off, you can't (easily) do it like you wanted; the problem is how to differentiate ...


6

you can use this function that jumps by google "get post by title" /** * Retrieve a post given its title. * * @uses $wpdb * * @param string $post_title Page title * @param string $post_type post type ('post','page','any custom type') * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. * @return mixed */ function ...


6

Also, run the slug from sanitize_title_with_dashes() through wp_unique_post_slug() to ensure that it's unique. It will automatically append '-2', '-3' etc. if it's needed.


6

No, forward slashes are not allowed to be used in slugs. However, they are automatically stripped out when trying to include slashes in a slug on the post editing screen. Slugs are sanitized by using sanitize_title(). Unfortunately, there is no easy way to explain what is and isn't allowed in a slug, let alone to give a simple set of rules to which valid ...


5

Figured out: function re_rewrite_rules() { global $wp_rewrite; // $wp_rewrite->author_base = $author_slug; // print_r($wp_rewrite); $wp_rewrite->author_base = 'autor'; $wp_rewrite->search_base = 'buscar'; $wp_rewrite->comments_base = 'comentarios'; $wp_rewrite->pagination_base = 'pagina'; ...


5

Filter template_include: add_filter( 'template_include', 'prefix_translate_template' ); function prefix_translate_template( $template ) { if ( 'category-' . __( 'news', 'your_textdomain' ) . '.php' === $template ) return 'category-news.php'; return $template; } But I think templates based on slugs are not a good idea in that case.


5

You probably have a tag with the same slug. You can't have any taxonomies with duplicate slugs. Either delete that other taxonomy, rename/change its slug, or change/rename this category. EDIT Ok, it turns out you can do this, if you don't mind programming the fix or directly executing the SQL or messing with PHPMyAdmin. What you need to do is add a new row ...


5

In WordPress, "---" and " -- " become em-dashes (— &#8212;) and "--" becomes an en-dash (— #8212;). The sanitize_title_with_dashes() function doesn't catch these. That function uses the databased copy, but the title displayed to the user always goes through a texturize function. So if we replace en/em dashes on their way into the database, ...


5

As long as haven’t touched the slug WordPress will generate a new one after you entered a title. Update To change other peoples slugs use a filter (not tested!): add_filter( 'wp_insert_post_data', 'prevent_numeric_slugs', 10, 1 ); function prevent_numeric_slugs( $post_data ) { if ( ! isset ( $post_data['post_title'] ) or ! is_numeric( ...


5

Do you mean post slug? You can try to make use of wp_unique_post_slug() that WP uses to generate those. If I remember right if slug you are trying to use is not unique it will be returned with numerical index appended.


5

Yes, this is possible, but if the plugin is creating a custom post type using the rewrite => array('slug' => 'post_type') parameter, then it's not likely that you're going to be able to replace the slug. Whenever custom post types are created, URL rewrite rules are written to the database. Depending on which action triggers the creation of the custom ...


5

The single_tag_title() function returns the tag title while you need the tag slug or ID for use in query_posts(). This should get you started: if ( is_tag() ) { $tag = get_queried_object(); $tag_title = $tag->name; // Same as single_tag_title() $tag_slug = $tag->slug; $tag_id = $tag->term_id; } ...



Only top voted, non community-wiki answers of a minimum length are eligible