• Resolved WriterDan

    (@writerdan)


    The documentation on the plugin page says that I should be able to put:

    -AMAZONPOLLY-ONLYAUDIO-START-
    -AMAZONPOLLY-ONLYAUDIO-END-

    for the “Audio Only” functionality, and:

    -AMAZONPOLLY-ONLYWORDS-START-
    -AMAZONPOLLY-ONLYWORDS-END-

    for the “Words Only” functionality.

    Neither of these seem to work for me. When I put these strings into my content at the appropriate locations, they just render the text string as shown on my front-facing pages.

    They’re also called “tags” in the documentation, so I tried to use these as html tags, like:

    <AMAZONPOLLY-ONLYAUDIO-START>

    and that makes these custom markers not show up on the front-facing page, but don’t work when it comes to the text-to-audio conversion.

    Any help would be appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor tstachlewski

    (@tstachlewski)

    Hi @writerdan,
    Are you using some kind of builders application to build your WordPress site (like Divi)? I have tested it just now, on fresh clean environment (check this: https://s3.amazonaws.com/aaaa-tomasj/Screen+Shot+2018-05-03+at+10.31.22+AM.png ) – and everything is working fine :/. Are you also sure that you are using latest plugin version?

    Cheers,
    Tomasz

    Thread Starter WriterDan

    (@writerdan)

    Custom theme and latest version of the plugin.

    So I changed nothing (theme/core/plugins) on the site, but this functionality seems to be working now. I verified three separate times yesterday that it wasn’t working, and now it is. Guess I’ll just have to watch and see if it starts misbehaving again to determine what might have been the issue.

    Thanks anyhow.

    Thread Starter WriterDan

    (@writerdan)

    Figured it out. I hadn’t enabled Amazon Polly for the article post yet.

    Seems like there should be a more robust way of doing things in this instance. Especially given the fact that WordPress is so amazing in this regard. So, here’s a small suggestion. I’ve made a couple shortcodes (for my own use) that take advantage of the power of the WordPress shortcode. They might be useful for you to implement into the plugin instead of using custom string-replace functionality.

    function amazon_polly_audio_only_shortcode($atts, $content = NULL) {
    

    global $post;

    
    

    $tagged_content = ”;

    	if($content!==NULL) {
    

    $tagged_content = do_shortcode($content);

    		if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
    

    $tagged_content = PHP_EOL.’-AMAZONPOLLY-ONLYAUDIO-START-‘.PHP_EOL.$tagged_content.PHP_EOL.’-AMAZONPOLLY-ONLYAUDIO-END-‘.PHP_EOL;

    		} else {
    

    $tagged_content = PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL.$tagged_content.PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL;

    		}
    

    }

    	return $tagged_content;
    

    }

    add_shortcode('polly_only_audio', 'amazon_polly_audio_only_shortcode');
    
    function amazon_polly_words_only_shortcode($atts, $content = NULL) {
    

    global $post;

    
    

    $tagged_content = ”;

    	if($content!==NULL) {
    

    $tagged_content = do_shortcode($content);

    		if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
    

    $tagged_content = PHP_EOL.’-AMAZONPOLLY-ONLYWORDS-START-‘.PHP_EOL.$tagged_content.PHP_EOL.’-AMAZONPOLLY-ONLYWORDS-END-‘.PHP_EOL;

    		} else {
    

    $tagged_content = PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL.$tagged_content.PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL;

    		}
    

    }

    	return $tagged_content;
    

    }
    `add_shortcode(‘polly_no_audio’, ‘amazon_polly_words_only_shortcode’);

    I’ve verified that this setup work for my use case. I’m not sure if the solution will need to be tweaked to work in a general case.

    I have another ticket open currently about style tags being converted to audio, and this solution will take care of that use case as well. I’ll close it out.

    Thread Starter WriterDan

    (@writerdan)

    Boy, that code block didn’t turn out at all. Here’s another go at it.

    
    function amazon_polly_audio_only_shortcode($atts, $content = NULL) {
    	global $post;
    
    	$tagged_content = '';
    	if($content!==NULL) {
    		$tagged_content = do_shortcode($content);
    		if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
    			$tagged_content = PHP_EOL.'-AMAZONPOLLY-ONLYAUDIO-START-'.PHP_EOL.$tagged_content.PHP_EOL.'-AMAZONPOLLY-ONLYAUDIO-END-'.PHP_EOL;
    		} else {
    			$tagged_content = PHP_EOL.'<!-- Amazon Polly not enabled on this post -->'.PHP_EOL.$tagged_content.PHP_EOL.'<!-- Amazon Polly not enabled on this post -->'.PHP_EOL;
    		}
    	}
    	return $tagged_content;
    }
    add_shortcode('polly_only_audio', 'amazon_polly_audio_only_shortcode');
    
    function amazon_polly_words_only_shortcode($atts, $content = NULL) {
    	global $post;
    
    	$tagged_content = '';
    	if($content!==NULL) {
    		$tagged_content = do_shortcode($content);
    		if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
    			$tagged_content = PHP_EOL.'-AMAZONPOLLY-ONLYWORDS-START-'.PHP_EOL.$tagged_content.PHP_EOL.'-AMAZONPOLLY-ONLYWORDS-END-'.PHP_EOL;
    		} else {
    			$tagged_content = PHP_EOL.'<!-- Amazon Polly not enabled on this post -->'.PHP_EOL.$tagged_content.PHP_EOL.'<!-- Amazon Polly not enabled on this post -->'.PHP_EOL;
    		}
    	}
    	return $tagged_content;
    }
    add_shortcode('polly_no_audio', 'amazon_polly_words_only_shortcode');
    

    Hope that’s better.

    Then to use the short codes, just wrap the content you want to include, like:

    
    [polly_no_audio]
    Some content here that I don't want to include in the audio version.
    [/polly_no_audio]
    

    Best.

    Plugin Contributor tstachlewski

    (@tstachlewski)

    Thx!
    Definitely will look into !

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘“Words Only” and “Audio Only” not working’ is closed to new replies.