Remove the article ID from Joomla content article URLs when SEF is enabled

If your Joomla site is not equipped with a super SEO app that will strip away that very visible article ID: /34-the-great-article-title-alias, Joomla 3 does have a 'hidden' parameter to make the URL read as /the-great-article-title-alias, but it requires some effort, and is worth it. Once done, it's yours for your everlasting Joomla life.

Create A Plugin For The Job

A System plugin will serve best for the task because it is loaded globally, unless instructed otherwise.

1. Create the folder which will contain all the files and give it a relative name
strip_article_id

2. Create the primary function file within the folder and keep the name similar to the folder for simplicity
strip_article_id.php

<?php defined('_JEXEC') or die();
/**
* @package      plg_system_strip_article_id
* @copyright   Copyright (C) AnySiteYouWantHere.com All rights reserved.
* @license      GNU General Public License version 2 or later; see http://www.gnu.org/licenses/
**/

class plgSystemStrip_Article_Id extends JPlugin {

      public function onContentPrepareForm($form, $data) {
   // global content configuration form
   if( $form->getName() == 'com_config.component' && JFactory::getApplication()->input->get('component') == 'com_content' ) {
      JForm::addFormPath(JPATH_PLUGINS.'/system/strip_article_id/');
      $form->loadFile('contentconfig', false);
   }
  }

}

3. Create the installer XML file within the folder and give it the same name as the function file

strip_article_id.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.7.0" type="plugin" group="system" method="upgrade">
   <name>System - Strip Article ID</name>
   <author>AnyWebSiteHere.com</author>
   <creationDate>06.17.2017</creationDate>
   <copyright>All Rights Reserved.</copyright>
   <license>license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
   <authorEmail>yourmail@yoursite.com</authorEmail>
   <authorUrl>http://www.yoursitehere.com</authorUrl>
   <version>1.0</version>
   <description>Strip Article ID From SEF URL</description>
   
   <files>
      <filename plugin="strip_article_id">strip_article_id.php</filename>
      <filename>index.html</filename>
     <filename>contentconfig.xml</filename>
   </files>
</extension>

4. Create the form control which will be shown in the content global configuration under the Articles tab, within the folder.
contentconfig.xml

<?xml version="1.0" encoding="utf-8"?>
<form>
   <fieldset name="articles">
      <field name="sef_advanced_link" type="radio" class="btn-group btn-group-yesno" default="1" label="Remove Article ID In URL">
         <option value="1">JYES</option>
         <option value="0">JNO</option>
      </field>
   </fieldset>
</form>

Be sure to add an empty index.html file to the folder or remove <filename>index.html</filename> from the installer .xml file.

5. Compress the folder as a .zip and install, enable, then go to System > Global Configuration and click Articles. The switch will be at the bottom of the page


Saturday, 12 August 2017 16:28  |   306 views

 

Copyright © 2017 CMSEnergizer.com. All Rights Reserved.
This website is powered by the Joomla!©™ 3 Website Framework | File download and article manager component by K2 | Advanced Module Manager and Modules Anywhere by NoNumber Elements | Website hosting and development by WebsiteDons

CMSEnergizer.com is owned and operated by Emuzement Net Inc, 4532 West Kennedy Blvd. Ste 180 33609 Tampa, Florida USA