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;








3















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.










share|improve this question






























    3















    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.










    share|improve this question


























      3












      3








      3


      1






      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 17 at 12:38









      cjbj

      11k103067




      11k103067










      asked May 16 at 16:38









      Marg9Marg9

      203




      203




















          2 Answers
          2






          active

          oldest

          votes


















          7














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





          share|improve this answer




















          • 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














          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





          share|improve this answer























          • 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











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



          );













          draft saved

          draft discarded


















          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









          7














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





          share|improve this answer




















          • 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















          7














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





          share|improve this answer




















          • 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













          7












          7








          7







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





          share|improve this answer















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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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












          • 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













          1














          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





          share|improve this answer























          • 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















          1














          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





          share|improve this answer























          • 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













          1












          1








          1







          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





          share|improve this answer













          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

          Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

          What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company