Is there any way to add HTML tag to Post Title?

header
typed.js
wordpress

(App Shah) #1

Yesterday I’ve added this to Crunchify Services site.

It took me long time to figure out where to put typed.js code. It seems WordPress doesn’t allow HTML tag to Post Title and hence i’ve directly modified theme template file for this effect.

I would like to know is there any way to add HTML tag to Post Title? Any clue?


(App Shah) #2

Hi Crunchify Readers - if you would like to implement your own Typed effect then I’ve just published complete tutorial here: http://crunchify.com/how-to-add-typewriter-typing-animated-text-effect-using-typed-js-to-wordpress-blog/

Happy Blogging.


(Alexandru Negoita) #3

This should do it, as I found it posted by a user on another website, picked up, edited, and used on our website as well:
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:
 * [br]
 * [span]something[/span]
 * [b]something[/b]
 * [strong]something[/strong]
 * [anchor url="http://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: http://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”


(App Shah) #4

This is great Alexandru… Thanks for detailed suggestion. I’ll apply this today and will update…


(david smith) #5

thanks is really great.


(Sahar Ali) #6

this is the best reply


(App Shah) #7

Sorry for late reply. It worked perfectly. I’ll publish a tutorial on Crunchify.com within few days.

Thanks again.


Copyright © 2018 Crunchify, LLC.  •  WordPress Services  •  Contact  •  Hosted at DiscourseHosting.