Post Type: Product Links

Manage affiliate links as products and show them anywhere with a Query Loop.

Lauren Gray Avatar

Post Type: Product Links lets you manage affiliate links as products in their own Shop section of your dashboard. Show them anywhere with a Query Loop block, and each product links straight to its affiliate URL.

Before you start

  • WordPress 5.8.3 or later
  • PHP 5.6 or later

Install

  1. In your dashboard, go to Plugins → Add New Plugin.
  2. Click Upload Plugin and choose the plugin zip file.
  3. Click Install Now, then Activate.

How to use

Add a product

  1. Go to Shop → Add New (the cart icon in the admin menu).
  2. Enter the product name as the title. Add a featured image, an excerpt and any content you want to show.
  3. In the editor sidebar, open the Product Link panel and paste your affiliate URL into the Product Link field.
  4. Optionally, assign a Product Section to group related products.
  5. Click Publish.

The All Product Links screen shows each product’s URL in a Product Link column. Click the field to select the URL for copying. You can also change the link from Quick Edit or set it for several products at once with Bulk Edit.

Group products into sections

Go to Shop → Product Sections to create sections, like categories just for your products. Sections can have parent sections and appear as a column in the products list.

Display products with a Query Loop

  1. Add a Query Loop block to a post, page or template.
  2. In the block settings, set the post type to Product Link.
  3. Design the loop with blocks such as Title, Featured Image and Excerpt. Turn on the link option for the title or image.

On the front end of your site, a product’s link points to its Product Link URL, not to a page on your site. So any linked title or image in the loop sends readers straight to the product.

Products don’t have their own pages. If someone visits a single product URL, they’re redirected to the shop archive at /shop/. Product Section archives use /shop/section-slug/.

Linked Title blocks in a product Query Loop use the default target and rel from Shop → Settings. To use different settings for one loop:

  1. Select the Title block inside the product Query Loop.
  2. In the sidebar, open Product Link Settings and turn on Override product settings.
  3. Use the Title block’s own link options to set the target and rel.

Migrate from Shop Page WP

Moving over from the Shop Page WP plugin? The built-in migration copies your products for you.

  1. Back up your site.
  2. Go to Shop → Migrate. You need administrator access to see it.
  3. Click Start migration.
  4. When it’s done, you’ll see “Migration completed successfully!”

The migration copies each published Shop Page WP product’s title, content, status, author, dates, featured image and URL into a new product. Its categories become Product Sections, with parent sections kept. Products that already exist with the same title and link are skipped, so it’s safe to run again. Your original Shop Page WP items aren’t deleted.

Settings

Go to Shop → Settings (the Product Settings screen).

  • Hide products from search: keeps products out of your site’s front-end search results. On by default.
  • Default product target: choose Open in same window (default) or Open in new window for linked product titles.
  • Default product rel: the rel attribute added to linked product titles, such as nofollow sponsored. Empty by default, so add your own values.

The target and rel defaults apply to linked Title blocks in a product Query Loop. They don’t change other linked blocks, such as a linked featured image.

Developer reference

For developers: hooks and functions you can use from your theme or a code snippet.

\SmallPlugins\ProductLinks\Links\get( $args = array() )

Function. Returns a product’s affiliate link. Pass array( 'page_id' => $id ) for a specific product; defaults to the current post.

\SmallPlugins\ProductLinks\Links\render( $args = array() )

Function. Prints the link (an <a class="button more-link" rel="nofollow">). Arguments: link (defaults to the current product’s link), text (defaults to “Check it out”) and new_tab (defaults to false).

\SmallPlugins\ProductLinks\Links\render(
	array(
		'link'    => \SmallPlugins\ProductLinks\Links\get( array( 'page_id' => 123 ) ),
		'text'    => 'Buy on Amazon',
		'new_tab' => true,
	)
);

The link is also saved as the product-link post meta, which is available in the REST API.

FAQs

Are links nofollow automatically?

No. Add nofollow (and sponsored, if you like) in Default product rel under Shop → Settings.

Does it work with other plugins?

A few touches are built in. The Yoast SEO meta box is hidden on product editing screens, along with two social sharing meta boxes. Products are also left out of the post search in WP Tasty’s Tasty Roundups.