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

          Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

          Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

          Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020