modified link-template.php in child theme
-
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.
-
Hallo @wdekleijn,
to override a parent theme’s template file (link-template.phpin this case) in a child theme, you typically don’t need to add any code to thefunctions.phpfile of your child theme. Instead, you just need to replicate the file structure of the parent theme in your child theme and place the modifiedlink-template.phpfile in the appropriate location within your child theme directory.Here’s what you need to do:
- 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 astyle.cssfile with the necessary information, including theTemplateheader referencing the parent theme’s directory name. - Within your child theme directory, create the same directory structure as the parent theme. For example, if the parent theme’s
link-template.phpfile is located inwp-content/themes/parent-theme/includes/, you should create a correspondingincludesdirectory within your child theme directory. - Place your modified version of
link-template.phpinto the appropriate directory within your child theme. So, in this example, you’d place it inwp-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.phpfile of your child theme is necessary for overriding template files.
I hope this is helpful 🙂
Greetings
Benjamin ZekavicaHi @benjamin_zekavica, thanks for your reaction. I was not aware of the required replication. The modified
link-template.phpis 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.ww.wp.xz.cn/reference/hooks/the_permalink/
Code Example inside your functions.phpfunction append_query_string($url) { return add_query_arg($_GET, $url); } add_filter('the_permalink', 'append_query_string');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
- Create a child theme if you haven’t already done so. This involves creating a new directory in the
The topic ‘modified link-template.php in child theme’ is closed to new replies.