Adding HTML tags to WordPress post titles •  SUPER WP HEROES

Adding HTML tags to WordPress post titles

Proposal presented by: SUPER WP HEROES

So, here is a little snippet of code that would allow you to add any HTML tag to your WordPress post titles as you see fit.

Useful for when you need to have a bolded word or line break at a specific place in the text.

Step 1: create your shortcode. Here are a few handy ones we use on WordPressHeroes.io


/**
 * Function to allow for HTML in widget titles
 * using a shortcode you can design yourself
 *
 * usage:
 * 
* something * something * something * [anchor url="https://domain.com/"]something[/anchor] * * Most of the widgets use a filter on widget title widget_title, but some custom widget might not apply or use this hook. * On those widgets, this method will not work. * * source: https://wordpress.stackexchange.com/a/136800/2015 */ // Original snippet add_filter('widget_title', 'do_shortcode'); add_filter('the_title', 'do_shortcode'); add_shortcode('br', 'so_shortcode_br'); function so_shortcode_br( $attr ){ return ' '; } add_shortcode('span', 'so_shortcode_span'); function so_shortcode_span( $atts, $content ){ $span = shortcode_atts( array( 'color' => '', ), $atts ); return ''. $content . ''; } add_shortcode('strong', 'so_shortcode_strong'); function so_shortcode_strong( $atts, $content ){ $a = shortcode_atts( array( 'class' => 'someclass', ), $atts ); return ''. $content . ''; } add_shortcode('b', 'so_shortcode_b'); function so_shortcode_b( $atts, $content ){ $b = shortcode_atts( array( 'color' => '', ), $atts ); return ''. $content . ''; }

Step 2: filter the HTML tag back out so that it doesn’t show up in your url’s ortags or any other place for that matter


//wp_title clean-up
function render_wp_title($title){
	echo preg_replace("~(?:[/?)[^/]]+/?]~s", ' ', $title);
}
add_filter( 'wp_title', 'render_wp_title', 98 );

Step 3: Add your titles … something like, “Uuuu, look at me, I’m a [ b ] cool [ /b ] title”

Approve Proposal

If you would like to join us and become a client then we’d be delighted to have you! You may confirm this proposal by signing it below.

SUPER WP HEROES provides top notch WordPress development services for over 10 years now.
We make use and build upon standard WordPress technology, thus creating light-weight and fast websites, ideal for your business!

Why should you build your website with us?


BECAUSE WE DELIVER!
JUST CHECK OUR TESTIMONIALS BELOW!

Floris de Haes

“We worked with more than 5 developers, over a period of more than 3 years of the Super WP Heroes team and had a very good experience. They were always available, handled fast when needed and delivered our requirements with quality. I can highly recommend Super WP Heroes.”

CEO @ Budget Energie


OR OUR LATEST PROJECT…


10 Adventures is one of the longest spanning WordPress Travel Website Development projects we worked on, and not because we had any trouble wrapping our brains around it, but because it is that big and complex.

VIEW WEBSITE

Upon accepting this proposal a WEB DESIGN & DEVELOPMENT AGREEMENT will be generated for you in the moment you pay the upfront. If you already have one with us, this stage will be skipped and this proposal will act as an integrated part of that framework agreement. An Upfront is required to begin work and the rest of the sum will be split through one or more Milestones. Your Company and Personal Data will be used in order to fulfill your order. We do not share your data with any third party that is not involved in the fulfillment of your order. Please review our Privacy Policy.