Randomized Tails Now Included

I just can’t leave well enough alone….

First it was the tagline, then it was syncing that up with <title> on the home page, and now I randomized the tails! This all started when I was looking to modify the designer credit at the bottom of the page; simply wanting to add my own by-line for the modifications.

Tail-line isn’t a word, so I’m not sure what exactly to call it; but often in the credits of pages I’d have some stupid line. I could have put that in the copyright text, which is separate from the design credit. But the text is larger and I wanted to integrate everything with the design credit. I’ve also been hacking on this WordPress theme; so I can probably tackle this.

functions.php

function randomtail() { 
    $lines = file("/var/www/pickmy/tails.txt") ; 
    return $lines[array_rand($lines)] ; 
} 

Literal copy/paste of the randomtext() function used for taglines; just a different function name and different text files. I could have just sync’d to the taglines; but I want the tails to be different…not just a duplicate from something you might see at the top.

inc/extras.php

function amphibious_credits_designer() {
	$tail = randomtail();
	printf( '<div class="credits credits-designer">%1$s <a href="%2$s" title="TemplatePocket">TemplatePocket</a> <span>&sdot;</span> Tagline & Tail Randomizers by pickmy.org <span>&sdot;</span> %3$s <a href="%4$s" title="WordPress">WordPress</a> <span>&sdot;</span> %5$s </div>',
		esc_html__( 'Amphibious Theme by', 'amphibious' ),
		esc_url( 'https://templatepocket.com' ),
		esc_html__( 'Powered by', 'amphibious' ),
		esc_url( 'https://wordpress.org', 'amphibious' ),
		$tail
	);

So inside inc/extras.php is the function called for the credits. There are actually multiple functions assigned to the action the theme calls, this is just the one we’re interested in. It took me a bit more poking at this than it should…largely because the way this printf statement is written and displayed confused me. But calling the randomtail() function, writing it to $tail, adding it’s place in the printf format argument, and adding the variable as that argument.

Update the file and Bob’s your uncle; we now have a different set of text being randomized in the footer.

Site comments disabled. Please use Twitter.