Simply use str_replace:
$text = str_replace(' ', '_', $text);
You would do this after your previous substr
and strtolower
calls, like so:
$text = substr($text,0,10); $text = strtolower($text); $text = str_replace(' ', '_', $text);
If you want to get fancy, though, you can do it in one line:
$text = strtolower(str_replace(' ', '_', substr($text, 0, 10)));
Related Posts:
- Remove/unset options field from backend Settings->General?
- How can I hook into and edit the text of a wp_nav_menu tag?
- Export User Info to CSV from Front End
- How to change date language without changing the entire site language?
- Getting the Current User
- How to sort results from a custom database table
- Initiate only latest version of a class
- Check if a user already voted [closed]
- WordPress if (is_page) translation on certain page
- Uploading video to google drive via frontend [closed]
- Using Font Awesome as post thumbnail
- admin-ajax.php responding with 0
- Deregister and Dequeue Stylesheets From a Plugin and Enqueue a Child’s Stylesheet/s
- How to use return in my custom function instead of echo
- Validate Uploaded Image using WordPress’ Built-in Functions?
- Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce
- How to properly insert a link to a template in WordPress?
- Difference between ‘type’ => ‘text’ and WP_Customize_Control
- Locating Global Variables
- $wpdb->flush(); breaks the loop
- get post based on category chosen in drop down – The ajax method
- Is there an equivalent to WP_Error object I can return in the case of a successful REST request?
- Extending the WP_Widget_Text class
- Set the background to a default image if there isn’t a specified “featured image”
- Proper syntax or method for keeping url in modified isotope / category links
- WordPress Access allowed to fewer pages till user logs in
- How to pass aa JS variable to PHP?
- Gutenberg block – Save PHP function’s output as HTML?
- different id for same element visual composer [closed]
- user_profile_update_errors hook not executing
- Adding number to date not working [closed]
- Changing the default object embed sizes?
- How to exclude tags and categories from a function?
- Programmatically inserting post through URL – when including wp-load.php, it’s redirecting to wp-admin/install.php
- Custom Theme’s “Preview Changes” Doesn’t Work for Previously Published Posts
- WordPress Stripping Colons?
- Custom Field IF/ELSE PHP
- Fatal error: Call to a member function query() on a non-object
- Run str_replace on title and save the output to a custom field
- Which function crops images in wordpress?
- Adding a line of text to php code
- wp_delete_comment takes two tries to delete – then deletes all comments
- WordPress Custom SQL Table with UserID Filter for results
- How to end a while loop when used in a fetch assoc function [closed]
- Why my loop isn’t working? [closed]
- How to use AJAX to call php page with parameter
- Menu Custom Data Attributes
- Pass return-path additional parameter in wp_mail
- How to get image from url from the database?
- WordPress meta_query >= &
- Change header on pages displaying taxonomy items
- How to override a plugins script
- Comparing Dates from custom field
- Prevent Company Name From Translating
- Displaying Slider in Front Page (home) using Customizr Theme
- Usage of var keyword in the core
- Taxonomy term description with style, only if the description exists?
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- PHP displaying wrong custom taxonomy images
- Page load timer?
- How to sort posts by active category in WordPress?
- wordprees multi-site in user panel add filter
- WordPress custom php script to match standard page layout
- copy fields value to another field
- Get parent category name when only child category is applied to a product
- Updated Php version from 5.4 to 7.2 and getting “PHP installation missing the MySQL extension needed by WordPress”
- Before & After Content – After Content directly below Before Content when using require_once
- Get Child of Child Pages in custom Menu
- Latest posts feed with a specific post always first
- Top Authors list by highest post views with Ajax pagination
- WordPress Post undefined error with Post Date (New to Wordpres Dev)
- From php web to wordpress conversion, href changes only in URL
- How can i put php code on the wordpress page?
- What’s the correct offset value for order ASC?
- Setting at job with shortcode not working
- How to solve 404 permalink errors on nginx server
- Ajax Load more CPT via shortcode
- Loop 1 user randomly
- Order by in foreach
- Sort by multiple options in custom field
- Query seems to be duplicated
- two sites, same code, different presentation
- WPMU schedule doesn’t execute actions
- ISOTOPE – Missing/Invalid Arguement Get Terms
- doubled content
- Adding if statement to content for homepage
- Add Condition if WPBakery Page Builder Used on Page or Not
- Data inserted in database, but ajax calls error function
- how to import contacts from php to wordpress
- How to add active class dynamically
- I’m not able to get access $wpdb in my php file in wordpress
- Submit cf7 form to cfdb as pdf/BLOB [closed]
- How to use url and amin-ajax.php
- WP – Ajax call back data printed in the console.log
- Dynamic Email Handler with ‘header (“Location: …’
- Grabbing value of input field inside of array
- Implement OAuth2 in custom plugin
- Count custom posts type and filter by tag
- Error with PHP 8
- How to create a User Role and give permission to only use Web Stories plugin?