• Resolved graphic_dev

    (@graphic_dev)


    I have created a child theme to override a theme that i bought. The original theme has a file called functions/shortcodes.php which has the following function:

    function ag_divider( $atts, $content = null ) {
        extract(shortcode_atts(array(
        ), $atts));
    
    	$out = '<div class="divider"><h5><span>'.do_shortcode($content).'</span></h5></div>';
    
        return $out;
    }
    add_shortcode('divider', 'ag_divider');

    How do I override this function in my child theme? All I want to do is change the <h5> to an <h2>, but I rather not do this in the original file.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’d suggest that you remove the original shortcode in your child theme’s function.php file and then set up a new version in the same file.
    https://codex.www.ads-software.com/Function_Reference/remove_shortcode

    Thread Starter graphic_dev

    (@graphic_dev)

    I can’t remove the shortcode from my child theme’s functions.php file… I tried adding the following in the original theme’s shortcodes.php:
    remove_shortcode( 'divider' );
    which works fine, so the code seems right. But it doesn’t work when I move that same code to functions.php in my child theme…

    What am I doing wrong?

    [please do not bump]

    try and use a ‘after_theme_setup’ section in functions.php of the child theme;

    example:

    add_action( 'after_setup_theme', 'my_ag_child_theme_setup' );
    
    function my_ag_child_theme_setup() {
       remove_shortcode( 'divider' );
       add_shortcode( 'divider', 'my_ag_divider' );
    }
    
    function my_ag_divider( $atts, $content = null ) {
        extract(shortcode_atts(array(
        ), $atts));
    	$out = '<div class="divider"><h2><span>'.do_shortcode($content).'</span></h2></div>';
        return $out;
    }

    Thread Starter graphic_dev

    (@graphic_dev)

    Thanks alchymyth, that worked perfectly!

    Cypher-kun

    (@cypher-kun)

    It helped my too.
    Thanks guys!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Override theme's shortcodes.php’ is closed to new replies.