Skip to content

Instantly share code, notes, and snippets.

@jreviews
Last active September 21, 2023 21:37
Show Gist options
  • Save jreviews/9fe21343db5064a3e27beb2665cd9d03 to your computer and use it in GitHub Desktop.
Save jreviews/9fe21343db5064a3e27beb2665cd9d03 to your computer and use it in GitHub Desktop.
Disable 4SEO in JReviews Listings

JReviews has always had a strong focus in SEO and comes with functionality to add Schema.org markup, Open Graph and Twitter tags. It also allows using internal features like media and custom fields as part of this functionality which is something 3rd party solutions cannot do unless support is added specifically for them.

If you are using 4SEO for your site, it will add all these SEO features for core functionality and some 3rd party solutions. However, this creates a problem with duplication in JReviews listings. JReviews has it's own data and in some cases may do things differently. So in this case, the recommended solution is to disable the 4SEO tags in JReviews listings to avoid duplication.

This can be done programatically using 4SEO hooks

If you are not using hooks yet, you'll need to create the file at:

  • /libraries/weeblr/forseo_functions.php (when using Joomla)

Then paste the code below to disable 4SEO in JReviews listing detail pages.

<?php
/**
 * 4SEO hooks file
 *
 * You can use 2 variables to access 4SEO content:
 *
 * $factory: access variables
 * $hooks: add handlers
 */

defined('WBLIB_EXEC') || die;

use JReviews\App\Models\JReviewsCategory;

function forSeoDisableForJReviews($injectData, $pageData) {
    $request = fwd_request();
        
    if ($request->option !== 'com_content' && $request->view !== 'article') {
        return $injectData;
    }

    if (JReviewsCategory::select('id')->whereOption('com_content')->find($request->catid)) {
        return false;
    }

    return $injectData;
}

$hooks->add('forseo_should_inject_seo_data', 'forSeoDisableForJReviews');
$hooks->add('forseo_should_inject_structured_data', 'forSeoDisableForJReviews');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment