Automatically remove characters from post title using functions.php -> Please help!

Discussion in 'WordPress' started by j0563, Jul 8, 2010.

  1. #1
    I am trying to insert a function that will automatically remove certain characters from my post titles. Here is what I have:

    function remove_chars($nicetitle) {
    	
    	$title = get_the_title();
    	
    	$removechars = array('%','?','!','(',')'); 
    	$nicetitle = str_replace($removechars, "", $title);
    
    	return $nicetitle;
    }
    add_filter('the_title', 'remove_chars');
    PHP:
    I think that the problem is that I'm calling the title incorrectly?... I have placed this in my functions.php.

    Can someone help steer me in the right direction as to why this is not working? Thanks!!
     
    j0563, Jul 8, 2010 IP
  2. j0563

    j0563 Guest

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    OK, I've been working on this, but still have not found a solution. Here is another attempt I made:

    
    
    function remove_chars() {
    	
    	$title = the_title();
    	$removechars = array('%','?','!','(',')'); 
    	$nicetitle = str_replace($removechars, "", $title);
    	
    
    
    	return $nicetitle;
    
    }
    add_filter('the_title', 'remove_chars');
    
    PHP:
    I still can't get this to work... could someone please give me a hand on this???
     
    j0563, Jul 9, 2010 IP