Featured Post

How to Integrate Google Tag Manager with Drupal 9 - An Easy Step-by-Step Tutorial

  Marketers are always seeking new ways to elevate website engagement and maximize interactivity. Yet, managing the countless third-party in...

How to Integrate Google Tag Manager with Drupal 9 - An Easy Step-by-Step Tutorial

 Marketers are always seeking new ways to elevate website engagement and maximize interactivity. Yet, managing the countless third-party integrations and tracking tools implemented to enhance their business can quickly become overwhelming and chaotic. That's when Google Tag Manager comes to the rescue. With its intuitive and user-friendly platform, managing, updating, and tracking the snippets, tags, and integrations on your website has never been easier. From improving website performance to boosting conversion rates, Google Tag Manager offers the solution to streamline your digital marketing efforts and revolutionize your online presence.

Drupal 9 makes integrating with Google Tag Manager easy and effortless. The Google tag manager module in Drupal lets you quickly add, modify and remove tags on your website without touching any code! Read this easy step-by-step guide to learn how to integrate your Drupal 9 site with your Google tag manager.

GTM with Drupal

What is Google Tag Manager and how can it help?

Google Tag Manager is like a toolkit. It has all the tools you need meticulously organized in one place. Tools like Google Analytics, Adwords, personalization tools, A/B testing tools, Remarketing, Native advertising pixels, and much more. All the integration tags can be stored in Google Tag Manager for better access and management. How can it help, you ask?

  • Marketers find it greatly beneficial as they don’t have to depend on developers to add and modify integration tags on the website. They can easily do it themselves.
  • Better organization of tags can help marketers’ access and manage their integrations easily.
  • Updating tags don’t require you to change them on multiple web-pages. 
  • Test if your tags get triggered on any event/action in the preview mode.
  • You can even check for formatting or security issues before deploying it to live.
  • Provides an extra layer of data security.

Integrating Google Tag Manager in Drupal 9

Drupal 9 integrates seamlessly with Google Tag Manager and installing it is also a breeze. Now that we know how useful Google Tag Manager is, let’s move on to integrating it with your Drupal 9 website.

Step 1 - Install the module

You can download the Google tag Manager module here.

Or run this command through composer with this command :

       
composer require 'drupal/google_tag:^1.4'

Install the GTM module

Step 2 - Configure the Module

In the admin toolbar, go to Configuration-> System -> Google Tag Manager

Configure the GTM module


Step 3 - Open Container Page

Once you click on Google Tag Manager, you will see a container page like this –

Open container page


Step 4 - Add a Container

Click on the Add container button. This is where you will add the Container ID that you had created previously when you signed up with GTM. If not done already, go here to signup and create a container ID for yourself (shown in the below steps).

Add a container


Step 5 - Create a Container

Under Account setup, give the Account name and your Country name.

Under Container setup, give the Container name and select the target platform as per your requirements.

Click on the Create button.

Google Tag Manager-Create n account


Step 6 - Get the Container ID

Once done, you will be able to see a popup screen that will display the code snippet that needs to be pasted in the head section. Look out for the Container Id which will look like an alphanumeric word and begins with “GTM”. Here it is “GTM-MXQN9XL”. Copy this code to your clipboard.

Tag Manager Code - get the container ID


Step 7 - Insert the Container ID

Head back to your Drupal setup where you had to add the container ID. Give a name for your container in the Label field and paste the previously copied container ID in the Container ID field. Save the configuration.

Insert container ID


Step 8 - And we’re all set!

To verify if the installation of Google tag manager has been successful in your Drupal site, go to the home page of your website and do an “Inspect Element”. If it has been installed properly, you should be able to see it within the <head> tag.

Check if GTM module is properly installed

What is the purpose of the php.ini file?

 The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality. The php.ini file is read each time PHP is initialized. in other words, whenever httpd is restarted for the module version or with each script execution for the CGI version.

How do you enable error reporting in PHP?

 PHP allows us to choose whether or not to display errors to users. There are three ways to enable or disable error reporting in PHP:

Method 1: You can turn the display error parameter in the php.ini file on or off. When it’s on, errors are shown; when it’s off, there are no errors shown or reported. To do this, locate the display error parameter in the php.ini file, then set its value to “on.” Restart the web server's various services. The PHP script's errors will now be visible to end users. Set the display error parameter to “off” to stop reporting errors. The off argument indicates that users won't see any errors.

Method 2: Using the mini set() function is the second way to enable or stop error reporting. The ability to modify the configuration options in the php.ini file is a built-in feature of the PHP programming language. It requires two inputs: the name of the setting you want to change and the value you want to assign.

Method 3: You can also utilize the error reporting() function, a native PHP function, to enable error reporting. This function controls which PHP faults are reported and sets the error reporting directive during runtime. Given that PHP has multiple error levels, this method also aids in setting the various levels for the runtime (duration) of your script. This function accepts parameters for error names like E ERROR, E WARNING, E PARSE, etc., allowing these errors to be reported.

Sachin vs South Africa Highlights HD🔥 First ODI Double Century hitter | India | Full Match Video

 




How to Create Custom Post Types in WordPress

 We only get three built-in content types at the backend when we install WordPress, i.e., posts, pages, and media. However, today WordPress has become quite flexible and advanced.

The approach to adding more post types also has expanded. The diversified usage demands more content types because posts, pages, and media are not enough, and here is where WordPress custom post type comes in handy.

What Is a WordPress Custom Post Type?

Custom post types are used to convert a regular WordPress website into a content management system. As the name suggests, you can use custom post types to create various content types for your website.

Besides that, one can find several post types available by default in WordPress installation, including:

  • Post – blog post
  • Page – static page
  • Attachment – attached media
  • Revision – post revision
  • Navigation Menu – nav menu
  • WordPress supports an unlimited number of Custom Post Types. You can create your custom posts and call them up wherever you want.
  • For example, if you run a News website and want to add a custom post type titled “News.” Once created, the news post-type would have its own menu in the WordPress dashboard admin area. Additionally, you can create multiple post types, such as Movies, Portfolios, etc.

What Is a WordPress Custom Post Type?

Custom post types are used to convert a regular WordPress website into a content management system. As the name suggests, you can use custom post types to create various content types for your website.

Besides that, one can find several post types available by default in WordPress installation, including:

  • Post – blog post
  • Page – static page
  • Attachment – attached media
  • Revision – post revision
  • Navigation Menu – nav menu
  • WordPress supports an unlimited number of Custom Post Types. You can create your custom posts and call them up wherever you want.

    For example, if you run a News website and want to add a custom post type titled “News.” Once created, the news post-type would have its own menu in the WordPress dashboard admin area. Additionally, you can create multiple post types, such as Movies, Portfolios, etc.

  • Follow the steps below to create a custom post type on a WordPress website:

    • Navigate to the function.php file from your WordPress theme directory
    • Add the following code to the function.php file
    1. /* Custom Post Type Start */
    2. function create_posttype() {
    3. register_post_type( 'news',
    4. // CPT Options
    5. array(
    6. 'labels' => array(
    7. 'name' => __( 'news' ),
    8. 'singular_name' => __( 'News' )
    9. ),
    10. 'public' => true,
    11. 'has_archive' => false,
    12. 'rewrite' => array('slug' => 'news'),
    13. )
    14. );
    15. }
    16. // Hooking up our function to theme setup
    17. add_action( 'init', 'create_posttype' );
    18. /* Custom Post Type End */
    • Once you’ve added the code, the News post-type will automatically appear in the admin area

    Creating a Custom Post Type

    • When creating custom post types, it is necessary to use init for the hook in add_action(), and the register_post_type() function will take the arguments
    1. /*Custom Post type start*/
    2. function cw_post_type_news() {
    3. $supports = array(
    4. 'title', // post title
    5. 'editor', // post content
    6. 'author', // post author
    7. 'thumbnail', // featured images
    8. 'excerpt', // post excerpt
    9. 'custom-fields', // custom fields
    10. 'comments', // post comments
    11. 'revisions', // post revisions
    12. 'post-formats', // post formats
    13. );
    14. $labels = array(
    15. 'name' => _x('news', 'plural'),
    16. 'singular_name' => _x('news', 'singular'),
    17. 'menu_name' => _x('news', 'admin menu'),
    18. 'name_admin_bar' => _x('news', 'admin bar'),
    19. 'add_new' => _x('Add New', 'add new'),
    20. 'add_new_item' => __('Add New news'),
    21. 'new_item' => __('New news'),
    22. 'edit_item' => __('Edit news'),
    23. 'view_item' => __('View news'),
    24. 'all_items' => __('All news'),
    25. 'search_items' => __('Search news'),
    26. 'not_found' => __('No news found.'),
    27. );
    28. $args = array(
    29. 'supports' => $supports,
    30. 'labels' => $labels,
    31. 'public' => true,
    32. 'query_var' => true,
    33. 'rewrite' => array('slug' => 'news'),
    34. 'has_archive' => true,
    35. 'hierarchical' => false,
    36. );
    37. register_post_type('news', $args);
    38. }
    39. add_action('init', 'cw_post_type_news');
    40. /*Custom Post type end*/

    $supports: Specifies that the post type is compatible and supports all essential features.

    $labels: Specifies that the post type is referred correctly to the admin area.

    $args: Specifies a permalink slug of the news and a menu position located just beneath the Posts menu.

    Now let’s take a look at before and after adding custom post features to our WordPress website.

    Before adding custom post features on WordPress

    – Before adding features

    After adding custom post features on WordPress
    – After adding features

    The steps above tell how to register WordPress custom post types to the backend of any theme. Now let’s learn how to add a custom post on a WordPress website.

    How to Create a New Custom Post on a WordPress Website

    You can create a new custom post on your WordPress website by following the steps below:

    • Click the registered custom post type, which in our case is “News.”
    • Click Add New.
    • Type the title and body of your post.
    • Type the excerpt, and set a featured image.
    • Click the Publish button to take the new custom post live.

    Create a New Custom Post on a WordPress Website

    How to Create a Template and Fetching List

    Creating a template and fetching a list requires creating a new file named template-news.php.

    • Place the newly created file in your theme folder.
    • Add the following code to the file:
    1. <?php
    2. /*Template Name: News*/
    3. get_header();
    4. query_posts(array(
    5. 'post_type' => 'news'
    6. )); ?>
    7. <?php
    8. while (have_posts()) : the_post(); ?>
    9. <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    10. <p><?php the_excerpt(); ?></p>
    11. <?php endwhile;
    12. get_footer();
    13. ?>

    Select a Template

    • Go to your WordPress dashboard
    • Click Pages > Add New
    • Create a new page named “News
    • Click Page Attributes on the right side and access the drop-down menu under Template
    • Select the new template “News
    • Click the Update button to set your template

    Refer to the image below for the visual representation of the above steps:

    Select template

    The image below represents the final display of your listing page:

    Listing Page Result

    How to Add Menu for Custom Post Type

    Add your custom post type as a part of the Menu options on your WordPress website by following the steps below:

    • Go to your WordPress dashboard
    • Navigate to Appearance > Menus
    • Add the News page to your main menu to display a navigational link to our newly created WordPress custom post type, News

    For further reference, check out the image below.

    Add Menu for Custom Post Type

    And this is how your website will look on the front end. Check out the image below:

    Front end page result

  • How to Create a Detail Page for Custom Post Type

    Create a “detail” page for custom post type by following the steps below:

    • Add a new file called single-news.php (located in your WordPress theme)
    • Add the following code to the file:
    1. <?php
    2. get_header();
    3. /* Start the Loop */
    4. while (have_posts()) : the_post();
    5. get_template_part('template-parts/post/content', get_post_format());
    6. endwhile; // End of the loop.
    7. get_footer();
    8. ?>

    Now it’s time to see what your detail page looks like:

    Detail Page for Custom Post Type

    Wrapping Up!

    You have now learned how to create a Custom Post Type in WordPress, which is quite complex but can be easily done by following the steps mentioned in this blog. Check out our other blog posts for more helpful guides on managing your WordPress site, such as reducing WordPress load times. Shall you have any queries or suggestions regarding the blog, feel free to comment below.

Popular Posts