Don't replace “|” with Empty String (“”) when generating slugs from titleWhat's the difference between hooks, filters and actions?Regenerate Slugs From Title of PostsHow do I replace title with my plugin?Empty string supplied as input when parsing contentReplace a word with a word in the URL stringWhy would apply_filters return a non-empty string, when the value returned is empty?Replace a 'Title' tag with a Custom FieldHow to auto update post title and slug with category name when post status is updatedString replace Wordpress Site Title'the_content' Filter delivers empty string with lengh (608)Remove and replace the “Category: from the_archive_title with custom text
How do I truncate a csv file?
What is the intuition behind uniform continuity?
The most awesome army: 80 men left and 81 returned. Is it true?
The oldest tradition stopped before it got back to him
Is it possible to kill all life on Earth?
Future enhancements for the finite element method
California: "For quality assurance, this phone call is being recorded"
What if you don't bring your credit card or debit for incidentals?
How can a single Member of the House block a Congressional bill?
How to detach yourself from a character you're going to kill?
Singlequote and backslash
Could a soul from the Soulmonger be restored in the ToA campaign after this event?
What is a simple, physical situation where complex numbers emerge naturally?
Order by does not work as I expect
Creating Fictional Slavic Place Names
Can you use a concentration spell while using Mantle of Majesty?
If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?
Can an old DSLR be upgraded to match modern smartphone image quality
arcpy.GetParameterAsText not passing arguments to script?
Accidentally cashed a check twice
What are the problems in teaching guitar via Skype?
Strange math syntax in old basic listing
Is the capacitor drawn or wired wrongly?
Is there any Biblical Basis for 400 years of silence between Old and New Testament?
Don't replace “|” with Empty String (“”) when generating slugs from title
What's the difference between hooks, filters and actions?Regenerate Slugs From Title of PostsHow do I replace title with my plugin?Empty string supplied as input when parsing contentReplace a word with a word in the URL stringWhy would apply_filters return a non-empty string, when the value returned is empty?Replace a 'Title' tag with a Custom FieldHow to auto update post title and slug with category name when post status is updatedString replace Wordpress Site Title'the_content' Filter delivers empty string with lengh (608)Remove and replace the “Category: from the_archive_title with custom text
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I work for an architecture company and our project names mostly go like this: house|something
, bridge|somewhere
, building|whatever
.
Now, when I want to add a new project named like that, WordPress automatically converts it to housesomething
, bridgesomewhere
and puts that as the slug. I'd much prefer to keep some kind of separator, e.g. house-something
, bridge-somewhere
instead.
So, how to make WordPress convert |
to -
and not Empty String
(""
)? I'm obviously tired of doing that manually all the time.
It seems to me that it's very simple to do. It takes just a simple search and replace kind of thing if one knows where to look (in the WP core or wherever), but I haven't the slightest idea where to look, or what code to execute.
filters slug title
add a comment |
I work for an architecture company and our project names mostly go like this: house|something
, bridge|somewhere
, building|whatever
.
Now, when I want to add a new project named like that, WordPress automatically converts it to housesomething
, bridgesomewhere
and puts that as the slug. I'd much prefer to keep some kind of separator, e.g. house-something
, bridge-somewhere
instead.
So, how to make WordPress convert |
to -
and not Empty String
(""
)? I'm obviously tired of doing that manually all the time.
It seems to me that it's very simple to do. It takes just a simple search and replace kind of thing if one knows where to look (in the WP core or wherever), but I haven't the slightest idea where to look, or what code to execute.
filters slug title
add a comment |
I work for an architecture company and our project names mostly go like this: house|something
, bridge|somewhere
, building|whatever
.
Now, when I want to add a new project named like that, WordPress automatically converts it to housesomething
, bridgesomewhere
and puts that as the slug. I'd much prefer to keep some kind of separator, e.g. house-something
, bridge-somewhere
instead.
So, how to make WordPress convert |
to -
and not Empty String
(""
)? I'm obviously tired of doing that manually all the time.
It seems to me that it's very simple to do. It takes just a simple search and replace kind of thing if one knows where to look (in the WP core or wherever), but I haven't the slightest idea where to look, or what code to execute.
filters slug title
I work for an architecture company and our project names mostly go like this: house|something
, bridge|somewhere
, building|whatever
.
Now, when I want to add a new project named like that, WordPress automatically converts it to housesomething
, bridgesomewhere
and puts that as the slug. I'd much prefer to keep some kind of separator, e.g. house-something
, bridge-somewhere
instead.
So, how to make WordPress convert |
to -
and not Empty String
(""
)? I'm obviously tired of doing that manually all the time.
It seems to me that it's very simple to do. It takes just a simple search and replace kind of thing if one knows where to look (in the WP core or wherever), but I haven't the slightest idea where to look, or what code to execute.
filters slug title
filters slug title
edited May 17 at 12:38
cjbj
11k103067
11k103067
asked May 16 at 16:38
Marg9Marg9
203
203
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
When WordPress inserts a post, it runs the title through a filter called sanitize_title
to get the slug. By default there is a function called santize_title_with_dashes
attached to this filter with priority 10. This function simply strips out the |
. If it is surrounded by spaces those spaces will be converted to hyphens.
So your task is to run a filter on the same hook before (say, priority 9) the default one and replace the |
with -
before it gets stripped away. Like this:
add_filter( 'sanitize_title', function ( $title )
return str_replace( ', 9 );
1
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)
– Marg9
May 17 at 11:30
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
add a comment |
If you put spaces in between the words and the separator | the permalink will automatically include dashes between the words. For instance try this as your post title:
house | something, bridge | somewhere
That results in the slug:
house-something-bridge-somewhere
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "110"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f338050%2fdont-replace-with-empty-string-when-generating-slugs-from-title%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When WordPress inserts a post, it runs the title through a filter called sanitize_title
to get the slug. By default there is a function called santize_title_with_dashes
attached to this filter with priority 10. This function simply strips out the |
. If it is surrounded by spaces those spaces will be converted to hyphens.
So your task is to run a filter on the same hook before (say, priority 9) the default one and replace the |
with -
before it gets stripped away. Like this:
add_filter( 'sanitize_title', function ( $title )
return str_replace( ', 9 );
1
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)
– Marg9
May 17 at 11:30
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
add a comment |
When WordPress inserts a post, it runs the title through a filter called sanitize_title
to get the slug. By default there is a function called santize_title_with_dashes
attached to this filter with priority 10. This function simply strips out the |
. If it is surrounded by spaces those spaces will be converted to hyphens.
So your task is to run a filter on the same hook before (say, priority 9) the default one and replace the |
with -
before it gets stripped away. Like this:
add_filter( 'sanitize_title', function ( $title )
return str_replace( ', 9 );
1
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)
– Marg9
May 17 at 11:30
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
add a comment |
When WordPress inserts a post, it runs the title through a filter called sanitize_title
to get the slug. By default there is a function called santize_title_with_dashes
attached to this filter with priority 10. This function simply strips out the |
. If it is surrounded by spaces those spaces will be converted to hyphens.
So your task is to run a filter on the same hook before (say, priority 9) the default one and replace the |
with -
before it gets stripped away. Like this:
add_filter( 'sanitize_title', function ( $title )
return str_replace( ', 9 );
When WordPress inserts a post, it runs the title through a filter called sanitize_title
to get the slug. By default there is a function called santize_title_with_dashes
attached to this filter with priority 10. This function simply strips out the |
. If it is surrounded by spaces those spaces will be converted to hyphens.
So your task is to run a filter on the same hook before (say, priority 9) the default one and replace the |
with -
before it gets stripped away. Like this:
add_filter( 'sanitize_title', function ( $title )
return str_replace( ', 9 );
edited May 25 at 7:42
shea
4,66232752
4,66232752
answered May 16 at 17:08
cjbjcjbj
11k103067
11k103067
1
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)
– Marg9
May 17 at 11:30
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
add a comment |
1
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)
– Marg9
May 17 at 11:30
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
1
1
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (
str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)– Marg9
May 17 at 11:30
Thank you very much for your suggestion. It indeed is correct, however there was one small mistake which I fixed and edited your post to make it right. (
str_replace()
doesn't change the subject string, it's output needs to be returned.) Up to now I haven't really looked too much into the WP Core, but I've gone through the manual for the mentioned functions and can say this practical example elucidated a lot for me. Now I actually understand how this solution works. Thanks again and bye :)– Marg9
May 17 at 11:30
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Glad to help. Thank you for correcting the error.
– cjbj
May 17 at 12:04
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
Understanding actions and filters is probably the first thing to dive into when trying to understand core. I wrote a small tutorial for that: wordpress.stackexchange.com/questions/265952/…
– cjbj
May 17 at 12:26
add a comment |
If you put spaces in between the words and the separator | the permalink will automatically include dashes between the words. For instance try this as your post title:
house | something, bridge | somewhere
That results in the slug:
house-something-bridge-somewhere
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
add a comment |
If you put spaces in between the words and the separator | the permalink will automatically include dashes between the words. For instance try this as your post title:
house | something, bridge | somewhere
That results in the slug:
house-something-bridge-somewhere
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
add a comment |
If you put spaces in between the words and the separator | the permalink will automatically include dashes between the words. For instance try this as your post title:
house | something, bridge | somewhere
That results in the slug:
house-something-bridge-somewhere
If you put spaces in between the words and the separator | the permalink will automatically include dashes between the words. For instance try this as your post title:
house | something, bridge | somewhere
That results in the slug:
house-something-bridge-somewhere
answered May 16 at 16:56
MichelleMichelle
2,37131929
2,37131929
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
add a comment |
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
Thanks for your post but this isn't really the solution as it requires that I change the titles, which is simply not how the company names it's projects, i.e. there shouldn't be any spaces.
– Marg9
May 17 at 11:36
add a comment |
Thanks for contributing an answer to WordPress Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f338050%2fdont-replace-with-empty-string-when-generating-slugs-from-title%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown