Apply add:filter to a specific page template
-
Hello WP forum, I hope someone here can help me.
I am using WordPress 4.4.1 and a twenty fifteen child theme.
In fuctions.php I have added the following code so that every time there is an asterisk (*) it is automatically surrounded by span tags sop that I can center align it in the css targeting the .auto-style class.add_filter( 'the_content', 'auto_word_style' ); function auto_word_style( $text ) { $text = str_replace( '*', '<span class="auto-style">* * *</span>', $text ); return $text;
But I need to run the code above only for a specific page template (my-template.php), so I changed the code into the following, but it doesn’t work.
if ( page_template ( "my-template.php") ) { add_filter( 'the_content', 'auto_word_style' ); function auto_word_style( $text ) { $text = str_replace( '*', '<span class="auto-style">* * *</span>', $text ); return $text; } }
Thanks in advance,
Beppe
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Apply add:filter to a specific page template’ is closed to new replies.