Auto Affiliate Links Shortcode

Below, you’ll find a detailed guide on how to add the Auto Affiliate Links Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Auto Affiliate Links Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Auto Affiliate Links Plugin and the shortcodes it provides:

Plugin Icon
Auto Affiliate Links

"Auto Affiliate Links is a convenient WordPress plugin. By simply installing wp-auto-affiliate-links, users can automatically add affiliate links to their blog posts, streamlining monetization."

★★★★✩ (38) Active Installs: 5000+ Tested with: 6.2.3 PHP Version: false
Included Shortcodes:
  • [autolink]

Auto Affiliate Links [autolink] Shortcode

The ‘autolink’ shortcode from wp-auto-affiliate-links plugin generates an automated affiliate link. It retrieves a link ID, checks if it’s enabled, fetches link data, and applies settings based on the link’s host.

Shortcode: [autolink]


Here is a list of all possible autolink shortcode parameters and attributes:

  • id – Unique number to identify the specific auto-affiliate link

Examples and Usage

Basic example – Displays an affiliate link by referencing its ID using the shortcode.

[autolink id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [autolink] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'autolink', 'aal_addlink_shortcode' );

Shortcode PHP function:

function aal_addlink_shortcode( $atts = array(), $content = null ) {
	$a = shortcode_atts( array(
		'id' => '',
), $atts );
	$id = intval( $a['id'] );
if ( ! $id ) {
  return $content;

	global $wpdb;
	$table_name = $wpdb->prefix . "automated_links";
	$myrows = $wpdb->get_results( "SELECT id,link,keywords,meta FROM ". $table_name ." WHERE id = '". $id ."' AND ( stats <> 'disabled' OR stats IS NULL ) LIMIT 1 " );
	if (count($myrows) <= 0){
    return $content;

	$autolink = $myrows[0];
	if(!isset($autolink->link)) return $content;
	$link = $autolink->link;
	$title = '';
	if(isset($autolink->meta)) {
	$meta = json_decode($autolink->meta);
		if((is_array($meta) || is_object($meta)) && isset($meta->title ))  $title = $meta->title;
		$ownhost = aal_get_host_from_parse(get_site_url());
		$linkhost = aal_get_host_from_parse($link);
		if($ownhost == $linkhost) { 
			$disclosure = get_option('aal_il_disclosure');
			$cssclass = get_option('aal_ilcssclass');		
			$targeto = get_option('aal_il_target');
			$relationo = get_option('aal_il_relation');
		else {
			$disclosure = get_option('aal_disclosure');
			$cssclass = get_option('aal_cssclass');
			$targeto = get_option('aal_target');
			$relationo = get_option('aal_relation');
		if($cssclass) $lclass = $cssclass . " aalshortcode";
		else $lclass = 'aalshortcode';

		if($relationo=='nofollow') $relo = ' rel="nofollow" ';
		elseif($relationo == 'sponsored') $relo = ' rel="sponsored" ';
		else $relo = '';
		if($targeto == '_blank' ) $taro = " target=\"_blank\" "; else $taro = '';


	$content = '<a href="'. $link .'" title="'. $title .'" class="'. $lclass .'" '. $relo .' '. $taro .'>'. $content .'</a>'. $disclosure;

    return $content;

Code file location:



Now that you’ve learned how to embed the Auto Affiliate Links Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.


Leave a Reply

Your email address will not be published. Required fields are marked *