How to Break Down a WordPress Post Title Into Two Parts

I am using a wordpress post to display testimonials, using the post content as the testimonial itself and its title for displaying the person giving the testimonial, and his company. In order to separate the name of the person from his company name and thus style them differently, I used the following code:

< ?php $title = $post->post_title; $namecompany = explode("-", $title); echo ($namecompany[0].' - '); ?> < ?php echo ($namecompany[1]); ?>

As you can see, we are using the $post->post_title variable which contains the title of the post, and then using the PHP function explode to break up the title into two parts based on the dash separator.

Related posts:

  1. Get Parent Page Title and Permalink in WordPress
  2. Remove Title and Editor From Post Editor and Replace by Custom Meta Box
  3. WordPress Plugin for Title Case
  4. WordPress Code for Formatting Fetched Post Content From DB
  5. WordPress 3 Custom Post Types Tutorials

One Comment

Got something to say? Feel free, I want to hear from you! Leave a Comment

  1. mylife says:

    Hello,

    I am working on site in wordpress, where all the Jobs are pulled from the external jobs sites, such as monster, indeed, simplyhired. jobs are getting published on site randomly. but I need to explode the jobs titles after specific ascii character ” – ” for ex Sales and Marketing Manager – Mortons Steakhouse – San Francisco, CA and extract last jobs Address from the title and call it in location column.

    Can somebody give me php function or other way for this, the ” – ” is common for all jobs titles published on site.

    please help waiting….

    Thanks

Leave a Comment

Let us know your thoughts on this post but remember to place nicely folks!