• I have modified link-template.php and want to use that version in a child theme. What code do I need to put in functions.php in the child theme folder.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hallo @wdekleijn,

    to override a parent theme’s template file (link-template.php in this case) in a child theme, you typically don’t need to add any code to the functions.php file of your child theme. Instead, you just need to replicate the file structure of the parent theme in your child theme and place the modified link-template.php file in the appropriate location within your child theme directory.

    Here’s what you need to do:

    1. Create a child theme if you haven’t already done so. This involves creating a new directory in the wp-content/themes/ directory with a unique name and adding a style.css file with the necessary information, including the Template header referencing the parent theme’s directory name.
    2. Within your child theme directory, create the same directory structure as the parent theme. For example, if the parent theme’s link-template.php file is located in wp-content/themes/parent-theme/includes/, you should create a corresponding includes directory within your child theme directory.
    3. Place your modified version of link-template.php into the appropriate directory within your child theme. So, in this example, you’d place it in wp-content/themes/child-theme/includes/.

    WordPress will automatically prioritize files in the child theme over those in the parent theme. So, when WordPress looks for link-template.php, it will first check the child theme’s directory and use that version if it exists. If not, it will fall back to the parent theme’s version.

    No additional code in the functions.php file of your child theme is necessary for overriding template files.

    I hope this is helpful ??

    Greetings
    Benjamin Zekavica

    Thread Starter wdekleijn

    (@wdekleijn)

    Hi @benjamin_zekavica, thanks for your reaction. I was not aware of the required replication. The modified link-template.php is in the /wp-includes/ directory, not in the /wp-content/themes/ folder or subfolders. So I understand a folder /wp-includes/ needs to be created in the theme child folder, in my case /content/themes/hueman-child/wp-includes/ and the modified file should be copied there to be prioritized. Right?

    cheers, Willem-Jan de Kleijn

    Hallo @wdekleijn,

    unfortunately you can’t override directly the file https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php

    But if you want to override the basic functions of WordPress, than it’s recommend to use our filter hooks. This PHP Functions allows you to override some specifics functionally of WordPress. You can write the function inside your functions.php inside your Child Theme.

    You can find it inside the function with the PHP Function: apply_filters(‘your_choosed_function_hook’, …

    For example: the_permalink()
    https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php#L27

    Docs: https://developer.www.ads-software.com/reference/hooks/the_permalink/

    Code Example inside your functions.php

    function append_query_string($url) {
        return add_query_arg($_GET, $url);
    }
    add_filter('the_permalink', 'append_query_string');
    Thread Starter wdekleijn

    (@wdekleijn)

    I’ve found out that the straightforward solution is to use filter by taxonomy in the previous post block. It has the options unfiltered, categories and tags. This answers my need. Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘modified link-template.php in child theme’ is closed to new replies.