PDA

View Full Version : HTML/Wordpress help



nbmedic
11-14-2011, 01:55 PM
For you experts this hopefully will be an easy questions for you to help me with.

How can I or can I take the title of my post and have that title repeated into the body of the post. For example I want to write on post and use it for several cities I serve selling homes but I do not want to have to change the name of the city multiple time in each post and would make my life easier if I could just paste the body and type in a new city in the title which would then pull it into certain areas within the blog.

Thanks in advance.

Basil
11-18-2011, 12:52 PM
I'm not very familiar with wordpress but I tested this myself and it should work.

Open up the functions.php file for the template you're using, it should be under /wp-content/themes/theme-name.

At the end of the file add something like this..


function replace_titles($content = '') {
return str_replace('TITLE', get_the_title(), $content);
}
add_filter('the_content', 'replace_titles');


It should replace any instance of the word "TITLE" in your posts with the actual title. You can change 'TITLE' to whatever keyword you want to use instead.

What this does is hook "the_content (http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content)" function in wordpress which contains the contents of our post, and applies our own function to it before it gets output to the page.

nbmedic
11-18-2011, 02:34 PM
You just saved me hours upon hours of time. Thanks you soooo much it worked perfectly!

Nate