Automated custom titles for your articles

Did you ever wish your clients will not need to write the same content twice, once in the title field, and another time in the custom fields?

Take a look at a video below which explains more, or continue the tutorial.

For example:
Let’s say your client is a record label owner, who need to publish articles of all the releases to the “Discography” section, now currently the client will probably need to fill the artist-name and the release-title of each release in both the article-title field and in custom-fields, which is absurd.

So in this tip I will show you how to create the articles titles from the data in the custom-fields and others.

First step

Install the bot_write_tab_customize plugin, and jump into its UI (Extensions > bot_wtc) then click on Additional js code

Inside the small window that just opened and paste the following code:

<script type="text/javascript">
	$(document).ready(function() {

		// Auto custom title	
		$('#page-article input.publish').click(function(){
			var section = $('select#section.list option:selected').val();
			var category = $('select#category-1.list option:selected').val();
			var title = $('#title').val();

			// Custom fields
			var cf1_Artist_Name   = $('input[name=custom_1]').val();
			var cf2_Release_Title = $('input[name=custom_2]').val();
			var cf3_Record_Label  = $('input[name=custom_3]').val();
			var cf4 = $('input[name=custom_4]').val();
			var cf5 = $('input[name=custom_5]').val();
			var cf6 = $('input[name=custom_6]').val();
			var cf7 = $('input[name=custom_7]').val();
			var cf8 = $('input[name=custom_8]').val();
			var cf9 = $('input[name=custom_9]').val();
			var cf10 = $('input[name=custom_10]').val();

			// Date fields
			var day = $('input[name="day"]').val();
			var month = $('input[name="month"]').val();
			var year = $('input[name="year"]').val();

			// Build the new title value base on sections and/or categories
			var custom_title = '';

			if (section == 'music' && category == 'chiptune'){
				custom_title = cf1_Artist_Name +' - '+ cf2_Release_Title +' ['+category+'/8bit]';
			}

			if (section == 'music' && category == 'trance'){
				custom_title = cf2_Release_Title +' - '+ cf1_Artist_Name;
			}

			if (section == 'music' && category == 'techno'){
				custom_title = cf2_Release_Title +' ['+cf3_Record_Label+']';
			}

			if (section == 'news'){
				custom_title = title +' ['+ month +'/'+ year +']';
			}

			// Set the new custom Title and/or URL-only titie
			if (section != 'videos'){
				$('#title').val(custom_title);
				//$('#url-title').val('');
			}
		});

	});
</script>

Second step

Edit the code:
Set the custom fields and others that you are going to be using to build the new title, in the next code you can see that I already set all the 10 custom fields as variables, and name 3 of them as just as I wanted to + added the date fields too:

			// Custom fields
			var cf1_Artist_Name   = $('input[name=custom_1]').val();
			var cf2_Release_Title = $('input[name=custom_2]').val();
			var cf3_Record_Label  = $('input[name=custom_3]').val();
			var cf4 = $('input[name=custom_4]').val();
			var cf5 = $('input[name=custom_5]').val();
			var cf6 = $('input[name=custom_6]').val();
			var cf7 = $('input[name=custom_7]').val();
			var cf8 = $('input[name=custom_8]').val();
			var cf9 = $('input[name=custom_9]').val();
			var cf10 = $('input[name=custom_10]').val();

			// Date fields
			var day = $('input[name="day"]').val();
			var month = $('input[name="month"]').val();
			var year = $('input[name="year"]').val();

Third step

Build the title value from the custom-fields that we had just set in the previous step, you can build it base on section or base on category or both just like in the next code:

if (section == 'music' && category == 'chiptune'){
				custom_title = cf1_Artist_Name +' - '+ cf2_Release_Title +' ['+category+'/8bit]';
			}

			if (section == 'music' && category == 'trance'){
				custom_title = cf2_Release_Title +' - '+ cf1_Artist_Name;
			}

			if (section == 'music' && category == 'techno'){
				custom_title = cf2_Release_Title +' ['+cf3_Record_Label+']';
			}

			if (section == 'news'){
				custom_title = title +' ['+ month +'/'+ year +']';
			}

Fourth step

The last part of the code that:

  1. Exclude the sections which you don’t want to create a custom title for their articles.
  2. Set the new title value we created in it’s place.
  3. Optionally – also reset the URL-only titie to the new title (you will need to un-comment it to work)
// Set the new custom Title and/or URL-only titie
			if ( section != 'videos' || section != 'events' ){
				$('#title').val(custom_title);
				//$('#url-title').val('');
			}

Fifth step (optional)

Hide the title field in the write tab – at the top of bot_write_tab_customize UI, below “Item” in the select-box select the “Title” field, and below “Hide in:” click on “Section List” then select the sections you want to hide the title field in them.

That’s all :)

Special thanks
Special thanks goes to redbot for helping me in this forum thread.

Video tutorial

The YouTube video accompanying this tutorial may be found below. Or, if you prefer Facebook, here is the video hosted there.

comments powered by Disqus