WP Manifestindependent plugin directory
manifest / content / mai-url-parameter-content

Mai URL Parameter Content

★ 0stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/maithemewp/mai-url-parameter-content/archive/refs/heads/develop.zip
Updates itself. It ships its own updater (Plugin Update Checker), so new versions appear under Dashboard → Updates.

This plugin contains 2 main features:

  1. A custom block to display or hide dynamic content based on URL parameters. Requires ACF Pro v6+. The block supports multiple URL parameters, optionally requiring specific values (case-insensitive).
  2. A programmatic way to add URL parameters (mostly for UTM campaigns) to all URLs inside a specific block or blocks.

Mai URL Parameter Content block

  1. All parameters set in the block need to exist on a specific page (case-insensitive) for the inner block content to display.
  2. If a block parameter has a value, it must match (case-insensitive) on the page.
  3. If a block parameter has an empty value, it only needs to exist on the page. The value doesn't matter.
  4. You can use {param_name} in the block content to display a parameter value in your content.

Mai URL Parameter Adder class

In the below example, tricky-footer is a custom class added to the Advanced settings "Additional CSS Class(es)" field on most blocks. Any block with that class will have key => value pairs added as URL parameters to all <a href> tags within that element's children.

/**
 * Adds URL parameters to blocks with custom classes.
 *
 * @param array $links
 * [
 *      'custom-class' => [
 *          'param1 => 'value1,
 *          'param2 => 'value2',
 *      ],
 *      'another-class' => [
 *          'param1 => 'value1,
 *          'param2 => 'value2',
 *          'param3 => 'value3',
 *      ],
 * ]
 *
 * @return array
 */
add_filter( 'mai_url_parameter_links', function( $links ) {
    $new = [
        'some-custom-class' => [
            'utm_source'   => 'website',   // e.g. newsletter, twitter, google, etc.
            'utm_medium'   => 'cta',       // e.g. email, social, cpc, etc.
            'utm_campaign' => 'affiliate', // e.g. promotion, sale, etc.
            'utm_content'  => '',          // (optional) Any call-to-action or headline, e.g. buy-now.
            'utm_term'     => '',          // (optional) Keywords for your paid search campaigns.
        ],
        'another-custom-class' => [
            'utm_source'   => 'website',
            'utm_medium'   => 'cta',
            'utm_campaign' => 'seo',
            'utm_content'  => 'check-this-out',
        ],
    ];

    return array_merge( $links, $new );
});