{"id":695,"date":"2020-07-01T13:51:31","date_gmt":"2020-07-01T18:51:31","guid":{"rendered":"https:\/\/ma.rcbla.se\/blog\/?p=695"},"modified":"2020-07-01T13:53:57","modified_gmt":"2020-07-01T18:53:57","slug":"match-and-replace-content-in-wordpress-the_title","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2020\/07\/match-and-replace-content-in-wordpress-the_title\/","title":{"rendered":"Match and replace content in WordPress the_title()"},"content":{"rendered":"<p>In a situation where content in <code>the_title()<\/code> needed to be italicized.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction fix_the_title( $title ) {\r\n\r\n  $new_title = $title;\r\n  $pattern = '\/Content to Match\/';\r\n  $replace = '&lt;em&gt;$0&lt;\/em&gt;';\r\n  $new_title = preg_replace($pattern, $replace, $new_title);\r\n\r\n  return $new_title;\r\n}\r\nadd_filter( 'the_title', 'fix_the_title' );\r\n<\/pre>\n<p>Add that to functions.php and you&#8217;re good.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a situation where content in the_title() needed to be italicized. function fix_the_title( $title ) { $new_title = $title; $pattern = &#8216;\/Content to Match\/&#8217;; $replace = &#8216;&lt;em&gt;$0&lt;\/em&gt;&#8217;; $new_title = preg_replace($pattern, $replace, $new_title); return $new_title; } add_filter( &#8216;the_title&#8217;, &#8216;fix_the_title&#8217; ); Add that to functions.php and you&#8217;re good.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-695","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/695","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=695"}],"version-history":[{"count":3,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/695\/revisions"}],"predecessor-version":[{"id":698,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/695\/revisions\/698"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}