• Resolved kfukawa

    (@kfukawa)


    Hi,

    First off, I love the plugin!

    The question I have is: Is it possible to change the text used for the link to something other than the title of the download?

    Ideally, I’d like to be able to add this as an argument to the shortcode – eg. [download id=”10″ linktext=”download our latest guide”]

    The guide is something that will be updated frequently, and may be referenced in many different ways and in different locations throughout the site. (i.e. it doesn’t make sense to use the document’s title attribute as the link text in all situations.)

    Can this be done using the Download Monitor plugin?

    Thanks for your help,

    Kevin.

    https://www.ads-software.com/plugins/download-monitor/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Angela

    (@g33kg0dd3ss)

    You can use a custom template to do this. ??

    Your template file (uploaded to /yourtemplate/download-monitor/ and named content-download-dllink.php, for example) might look something like:

    <?php
    /**
     * Download link custom template
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    ?>
    <a href="<?php $dlm_download->the_download_link(); ?>">Download Our Latest Guide</a>

    …And wherever you want to show the link, use:

    [download id="10" template="dllink"]

    Your other [download] shortcodes will still use the default template from your Download Monitor settings.

    Hope this helps! ??

    Thread Starter kfukawa

    (@kfukawa)

    Hi, and thanks for your suggestion.

    While this looks like it would work for all links that I wanted to use the exact same link text for, (in this case “Download our Latest Guide”,) ideally I’d like to be able to change this text on a case-by-case basis. Otherwise, I’d need to create a different template for each text variation, which could be quite cumbersome.

    Is there some other way to achieve this flexibility with this otherwise perfect plugin?

    Thanks again for your help,

    Kevin.

    Thread Starter kfukawa

    (@kfukawa)

    Also wanted to add that if there were an add-on that included this feature, I’d definitely be interested in making a purchase.

    Thanks,

    Kevin.

    Angela

    (@g33kg0dd3ss)

    True, it would require a lot of individual templates if every link had different text. Hopefully the plugin author will take your suggestion under advisement. ??

    Plugin Contributor Barry Kooij

    (@barrykooij)

    Hey all,

    First of, thanks g33kg0dd3ss for helping out by helping other people! It’s very appreciated.

    Regarding the custom template suggest, this is the correct approach and I’m afraid it’s not possible to add custom attributes to the shortcode as they would not be passed to the custom template.

    Sorry about the bad news.

    Kind Regards,

    Barry Kooij

    Thread Starter kfukawa

    (@kfukawa)

    Hi Barry,

    Thanks for your reply, and for developing and maintaining this free plugin. It’s too bad that adding custom attributes to the shortcode isn’t an option. Unfortunately, not being able to change the link text on a case-by-case basis is a deal-breaker for me.

    Thanks again,

    Kevin.

    So this is a super late reply, but I was struggling with the exact same issue, and it seemed crazy to me that there wasn’t a way to use your own text for download links. In the end, the solution I came up with is pretty simple: just create your own shortcode:

    function vnmWP_customDMShortcode($atts, $content = null) {
    	$attributes = shortcode_atts(array(
            'id' => '',
            'class' => '',
        ), $atts);
    	
    	$download = new DLM_Download($attributes['id']);
    	
    	if (!$download->exists()) {
    		return __('This download does not exist');
    	}
    	
    	ob_start();
    	
    	?>
    	
    	<a href="<?php echo $download->get_the_download_link(); ?>" class="<?php echo $attributes['class']; ?>">
    		<?php echo $content; ?>
    	</a>
    	
    	<?php
    	
    	$returnString = ob_get_clean();
    	
    	return $returnString;
    }
    
    add_shortcode('mydownload', 'vnmWP_customDMShortcode');

    And then use it like so:

    [mydownload id="406" class="button primary"]Download our latest guide[/mydownload]

    I personally put this in a plugin, but it could just as easily be added to your theme’s functions.php file.

    I threw in the ability to add classes as an attribute, but with this code you could effectively customise the DLM links however you wanted.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Possible to change link text from Title?’ is closed to new replies.