How to remove the article ID from article URLs when SEF is enabled

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
User avatar
websitedons
I've been banned!
Posts: 393
Joined: Sat May 27, 2017 9:42 am

How to remove the article ID from article URLs when SEF is enabled

Postby websitedons » Sat Jun 17, 2017 11:56 pm

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.

The parameter exists within the build() function of components/com_content/helpers/legacyrouter.php
Line: 62: $advanced = $params->get('sef_advanced_link', 0);, and it defaults to disabled, you just need to create a switch to put it to work.

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

Code: Select all

<?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

Code: Select all

<?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

Code: Select all

<?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.

The Output
the-output-switch.jpg


das it!
You do not have the required permissions to view the files attached to this post.

jonBuckner1
Joomla! Explorer
Joomla! Explorer
Posts: 305
Joined: Mon Nov 12, 2012 9:08 am

Re: How to remove the article ID from article URLs when SEF is enabled

Postby jonBuckner1 » Sun Jun 18, 2017 1:38 am

Suuuuuuuuuperb!

Forum post of the century :D

nstojcic
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Oct 05, 2017 5:22 pm

Re: How to remove the article ID from article URLs when SEF is enabled

Postby nstojcic » Thu Oct 05, 2017 5:29 pm

You are the KING! :D

tomytran
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 238
Joined: Mon Dec 14, 2009 1:52 pm
Location: www.tomytran.com
Contact:

Re: How to remove the article ID from article URLs when SEF is enabled

Postby tomytran » Sun Nov 12, 2017 9:51 am

Hello author,

Thank you for your system plugin package guide, I do follow your steps and I can see it appears as in your picture in my website and I intend to pack it on and share a package on this for any free use. But I still see ID on my article links ?

Any advice would be appreciated.

Thank you.
@ TOHA GROUP [ Tư vấn Quản trị, Marketing & Truyền thông +84 24 3996 4018 http://toha.us ]

<< Chăn ga gối đệm (nệm drap) an toàn cho sức khỏe, giấc ngủ và nghỉ ngơi http://kona.com.vn >>

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 23672
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: How to remove the article ID from article URLs when SEF is enabled

Postby Per Yngve Berg » Sun Nov 12, 2017 10:59 am

This information is outdated. There is a new router in 3.8 where you can do this. See the 3.8 version announcement.

webgyrl
Joomla! Explorer
Joomla! Explorer
Posts: 435
Joined: Sun Jun 11, 2006 7:31 am
Location: Planet Earth Most of the Time

Re: How to remove the article ID from article URLs when SEF is enabled

Postby webgyrl » Tue Nov 14, 2017 1:41 pm

Per Yngve Berg wrote:This information is outdated. There is a new router in 3.8 where you can do this. See the 3.8 version announcement.


Where is the announcement and how can I get rid of the IDs?
Always learning...

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 23672
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: How to remove the article ID from article URLs when SEF is enabled

Postby Per Yngve Berg » Tue Nov 14, 2017 9:20 pm

https://www.joomla.org/announcements/release-news/5713-joomla-3-8-0-release.html

Article Manager->Options->Integration->URL Routing=Legacy/Modern
Last edited by Per Yngve Berg on Tue Nov 14, 2017 9:30 pm, edited 1 time in total.

webgyrl
Joomla! Explorer
Joomla! Explorer
Posts: 435
Joined: Sun Jun 11, 2006 7:31 am
Location: Planet Earth Most of the Time

Re: How to remove the article ID from article URLs when SEF is enabled

Postby webgyrl » Tue Nov 14, 2017 9:24 pm

Thanks a million Per!
Always learning...


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: No registered users and 8 guests