{"id":317,"date":"2013-01-04T11:55:51","date_gmt":"2013-01-04T17:55:51","guid":{"rendered":"http:\/\/www.marcblase.com\/blog\/?p=317"},"modified":"2013-01-04T12:33:14","modified_gmt":"2013-01-04T18:33:14","slug":"wordpress-string-replace","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2013\/01\/wordpress-string-replace\/","title":{"rendered":"WordPress String Replace"},"content":{"rendered":"<p>I&#8217;ve been working on a site for a fancy client and they need to maintain their brand identity at all costs. So, that means even though their name contains a hyphen, it must NEVER break onto a new line which would split the name.<\/p>\n<p>Tried a couple different methods: javascript and php. Since the site is built in WP I went with the php method. Here it is:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction dont_break_lc($content){\r\n\treturn str_replace('fancy-name', '&lt;span style=&quot;white-space:nowrap&quot;&gt;fancy-name&lt;\/span&gt;', $content);\r\n}\r\nadd_filter('the_title', 'dont_break_lc');\r\nadd_filter('the_content', 'dont_break_lc');\r\nadd_filter('the_excerpt', 'dont_break_lc');\r\n<\/pre>\n<p>There are still a couple of problems with this solution. <code>str_replace<\/code> is case dependent so I have to repeat the function for Mixed Case and UPPER CASE occurrences so it shows up as <code>dont_break_Mc()<\/code> and <code>dont_break_UC()<\/code> in my functions.php file.<\/p>\n<p>I should add that I settled on the CSS nowrap solution so the site validated. <code>&lt;nobr&gt;<\/code> is more elegant and works without CSS, but c&#8217;mon , who disables CSS these days?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on a site for a fancy client and they need to maintain their brand identity at all costs. So, that means even though their name contains a hyphen, it must NEVER break onto a new line which would split the name. Tried a couple different methods: javascript and php. Since the site [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,32],"tags":[],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-coding","category-design"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":5,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}