Support » Developing with WordPress » Add Character in front of headings in RSS feed content

  • Resolved InHouse

    (@inhouse)


    Is it possible to add a character in front of all headings found in the_content of an RSS feed?

    For example, could I somehow run a PHP str_replace filter which reads ‘the_content’, finds any <h3>Something</h3> and adds and ‘ndash’ like this: <h3>&ndash; Something</h3>?

    It would need to only run on the RSS feed. Not sure if a function/filter is the way to do this or some kind of RSS feed. Any information is appreciated!

    I should also mention that this is for a custom post type (‘wod’) feed only.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Yes, there are filters for the feed. You should probably check for the correct post type in the filter.

    content_feed docs

    Thread Starter InHouse

    (@inhouse)

    Thanks @joyously

    For anyone else this may help, here’s what I ended up adding to my function.php file. My goal was to add a dash in front of all <h4> tags.

    
    function wod_feed_headers($content) {
    	if ( 'wod' === get_post_type() ) {
    	   $content = str_replace( array('<h4>'), '<br/><p></p><h4>&ndash; ', $content );
    	   return $content;
    	}
    }
    add_filter( "the_content_feed", "wod_feed_headers" );
    

    So, you didn’t check to see if it’s your custom post type? You will change all post types?

    Thread Starter InHouse

    (@inhouse)

    Good call @joyously ! I added a check to my previous reply above.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Character in front of headings in RSS feed content’ is closed to new replies.