WordPress,使用子主题,如何编辑功能

WordPress, using child theme, how can I edit a function

我正在使用 style.css 到 "add" 样式作为主题 - 所以当我更新主题时它不会被覆盖。

如何用函数实现同样的效果?

假设我有一个功能(在父主题中),

function interio_gmap_shortcode($atts) { .... .... $str .= ' <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false**&language=iw**"></script>

这是我要添加的- &language=iw ,它在父主题中不存在。

我怎样才能做到这一点?

如果您 creating a child theme 正确,您应该有自己的文件夹,里面有一个 styles.css 和一个 functions.php

要覆盖您所描述的函数,您需要从其原始位置(父主题的 functions.phpshortcodes.php)复制 php 函数,然后在子主题 functions.php 中进行所需的更改。

这取决于父主题是否被编码为允许覆盖该功能。如果是这样,它可能看起来像:

if (!function_exists('interio_gmap_shortcode')) {
    function interio_gmap_shortcode($atts) {
    ...

在这种情况下,您可以将函数复制到您自己的functions.php文件中并进行更改。在父 functions.php 运行时,您的函数已经存在并且将被使用。

如果父 function.php 不是 编码类似这样的代码,那么将函数复制到您的 function.php 将导致 "Duplicate Function"错误。

在这种情况下,您需要使用不同的名称创建自己的函数并改用它。