php 覆盖父函数,在子主题中覆盖父主题函数

我在子主题中有一些要覆盖的功能, 但继续获取无法重新声明langs_content()。

我用了很多资源进行故障排除, 有些应该直接说明, 但我无法解决

function enqueue_parent_theme_style() {

wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

}

add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style' );

function enqueue_child_theme_style() {

wp_enqueue_style( 'child-style', get_stylesheet_directory_uri().'/style.css' );

}

//require_once( get_stylesheet_directory() . '/functions.php');

add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_style', 100 );

if ( ! function_exists( 'langs_content' ) ) {

/*

* My Awesome function is awesome

*

*/

function langs_content( $atts, $content = null ) // shortcode lang

{

$lang = the_lang();

extract( shortcode_atts( array(), $atts ) );

$langs_content = '';

if(in_array($lang, $atts))

{

$langs_content .= do_shortcode($content);

}

return $langs_content;

}

add_shortcode('lang', 'langs_content');

}

?>

#1

真的很简单!从init钩子中删除简码, 然后添加新的;-)

像这样 :

/******

* Inside parent functions.php (don't touch this!)

******/

function test_shortcode() {

return "Hello World from parent theme";

}

add_shortcode('test_shortcode', 'test_shortcode');

/******

* Inside child functions.php

******/

function child_test_shortcode()

{

return "Hello World from child theme";

}

function remove_parent_theme_shortcodes()

{

remove_shortcode('test_shortcode');

// Add our new function with the same shortcode

add_shortcode('test_shortcode', 'child_test_shortcode');

}

// Remove the shortcode with init hook

add_action('init', 'remove_parent_theme_shortcodes');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值