Different ways to display title

The second form can be handy too: We can also use the third parameter: the_title( $before, $after, $echo ); to assign the title to a variable. Here’s an example: $title = the_title( ‘<h1 class=”entry-title”>’, ‘</h1>’, false ); This can also help reducing the use of <?php ?> delimiters. Here’s an example from the Twenty Fifteen … Read more

How do I use the same post slug for different Categories?

Using Parent-Child Page (Recommended) If you don’t have to have categories & posts, then this can be easily achieved using parent-child pages (not posts). For example, say you have three pages like: www.example.com/category-one/ www.example.com/category-two/ www.example.com/category-three/ Now you can have child pages for the above pages with slug email, e.g. www.example.com/category-one/email www.example.com/category-two/email www.example.com/category-three/email This is possible … Read more

Minimal custom permalink structure

Hi *@Bobby Jack:* You’ll have absolutely zero problem given your number of pages and posts. If you were looking at 5000, 10k, 25k pages or more, then start to worry. And the real problem is with categories as the URL base in the current implementation of WordPress’ URL routing (which I hope to see changed … Read more

Rewrite custom post type rss feed links

Put this in a plugin or functions.php: function feed_rewrite( $wp_rewrite ) { $feed_rules = array( ‘feed/portfolio’ => ‘index.php?post_type=post&feed=rss2’ ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } // refresh/flush permalinks in the dashboard if this is changed in any way add_filter( ‘generate_rewrite_rules’, ‘feed_rewrite’ ); When you’ve done that, go to the permalinks page and resave to flush … Read more

How to automatically generate a unique random slug

Use the function wp_unique_post_slug(). Do not reinvent the wheel, this one is quite tricky. Usage: $unique_slug = wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ); Then you can test if $slug === $unique_slug and generate a new one if the test fails. You can find the function in wp-includes/post.php. It ends with a filter ‘wp_unique_post_slug’, so … Read more

How to prevent apostrophes and quotes from appearing in permalinks?

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, … Read more