AtlasVoice Text To Speech

⌘K
  1. Home
  2. Docs
  3. AtlasVoice Text To Speech
  4. FAQ
  5. How to Include PHP-Built Custom Field Text in Bulk MP3 Audio

How to Include PHP-Built Custom Field Text in Bulk MP3 Audio

Bulk MP3 generation in AtlasVoice Pro makes the audio from your WordPress admin, before anyone visits the page. It does not open the page, so it cannot use Read content from DOM or your custom CSS selectors. It reads the post title and the post content.

If part of your page is built with PHP in your theme, for example from Advanced Custom Fields, that text is not in the post content. A small snippet can add it, so the bulk audio includes it.

Add the text with a snippet

Add this with the free Code Snippets plugin (set it to run everywhere), or in your child theme’s functions.php file. Change the post type and the field names to match your site.

add_filter( 'tta__content_description', function ( $text, $raw, $post_id ) {
	// Only the post types that use these fields.
	if ( 'page' !== get_post_type( $post_id ) ) {
		return $text;
	}

	// Build the text the same way your template does.
	// get_field() is from Advanced Custom Fields; change the field names to yours.
	$parts = array(
		get_field( 'intro_text', $post_id ),
		get_field( 'closing_text', $post_id ),
	);

	$extra = wp_strip_all_tags( implode( '. ', array_filter( $parts, 'is_string' ) ) );

	return $extra ? $text . ' ' . $extra : $text;
}, 20, 3 );

If your template joins or changes the fields with PHP, put the same logic here. The text is added after the post content, so arrange it in the order you want it read.

Generate the audio

  1. Open your posts or pages list in WordPress and select the items you want.
  2. Choose AtlasVoice Generate MP3 File in the Bulk actions menu and click Apply.
  3. Check the text shown for each item. Your added text should be at the end.
  4. If an item already has an MP3, tick the regenerate option on that screen, then start the generation.

Good to know

  • Once a post has its MP3, the player plays that file. Visitors do not start a new generation.
  • With Read content from DOM on, a post with no MP3 yet still gets its audio from the page text and your CSS selectors, so the two texts can differ. Keep the snippet in line with what your selectors read.
  • Fields you tick in the ACF setting under Compatibility are not added by bulk generation at the moment. Use the snippet for those fields as well.
  • Text that only appears in the browser, such as content loaded by JavaScript, cannot be included this way.

Need help?

If the text on the bulk screen is not what you expect, contact our support team and tell us your AtlasVoice version and which fields you use.

How can we help?