I am using text widget in page, my title is too long and i want to make (Br)break in particular place, but i can not. After saving (br)break is gone, also tried (nbsp) but same result came. How to overcome?
3 Answers
You can work around that by passing widget_title
through a filter :
function custom_widget_title( $title ) {
$title = str_replace( '__br__', '<br/>', $title );
return $title;
}
add_filter( 'widget_title', 'custom_widget_title' );
Now use __br__
in your widget title instead of <br/>
and the code will replace it.
Note: You need to put the code in your theme's functions.php
file.
You can't use an HTML in the title. Leave the title empty and put the title as part of the HTML of the widget. Apply specific CSS to the widget to make it look like a normal text widget.
-
it's for client purpose. Client change it dynamically, so it has to be in title of text widget. Aug 25, 2014 at 6:39
-
If you have additional constraints you should specify them in the question. Anyway I fail to see the contradiction, if a client knows enough HTML to use the text widget then it should not be a big problem for him to have the title as part of the text. Inserting <br> in the title also requires some knowledge of HTML Aug 25, 2014 at 9:04
Since post_title
and post_name
(url-part of the page) values depends on each other I will not recommend you using HTML inside page titles. It may leads weird data generated
Title: "foo<br>bar";
Slug(URL): "/foobrbar";
, but you can create a meta_field
to store HTML and output it.
1) Create a custom field HTML_TITLE_CUSTOM_FIELD_NAME
and fill in with your HTML title data;
2) Update your template files changing the title output logic as on example:
<?php
$html_title = get_post_meta($post->ID, "HTML_TITLE_CUSTOM_FIELD_NAME", true);
if ($html_title) { ?>
<h1><?php echo $html_title; ?></h1>
<?php } else { ?>
<h1><?php the_title(); ?></h1>
<?php } ?>