[Support request] PHP with new Elements->Hook

Home Forums Support [Support request] PHP with new Elements->Hook

Home Forums Support PHP with new Elements->Hook

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #924712
    Inna

    Hello,

    I’m trying to bring most of my PHP code from one of the plugins I have used before to the new Elements->Hook which as I understood can execute PHP.

    The code I’m playing with is simple JetPack “Related posts” removal which works perfectly using the old plugin to execute php but doesn’t work with Elements->Hook.

    <?php
    function jetpackme_remove_rp() {
    if ( class_exists( ‘Jetpack_RelatedPosts’ ) ) {
    $jprp = Jetpack_RelatedPosts::init();
    $callback = array( $jprp, ‘filter_add_target_to_dom’ );

    remove_filter( ‘the_content’, $callback, 40 );
    }
    }
    add_action( ‘wp’, ‘jetpackme_remove_rp’, 20 );
    ?>

    The Hook I’m creating has options like:

    Hook: before_header
    Execute Shortcodes: On
    Execute PHP: On
    Priority: 0 or 100 (doesn’t work with both)
    Display rules Location: Entire Site

    But the code doesn’t work. What am I doing wrong? Btw I don’t insert this hook as shortcode in to posts or pages. I’m thinking if Location is set to: Entire Site the code should run automatically?

    Thank you,
    Inna.

    #924734
    David
    Staff
    Customer Support

    Hi there,

    so Hooks come in two varieties – Action ( add_action ) and Filter ( add_filter ). The code you have is already hooking the function into the WP hook. So this cannot be added inside another hook.

    That code has to be added to your theme function file or via the Code Snippets plugin.

    #924880
    Inna

    Thank you for explanation. Now, if I remove the function call and put just the code in to gp hook it works.

    if ( class_exists( ‘Jetpack_RelatedPosts’ ) ) {
    $jprp = Jetpack_RelatedPosts::init();
    $callback = array( $jprp, ‘filter_add_target_to_dom’ );

    remove_filter( ‘the_content’, $callback, 40 );
    }

    Thank you ). Happy now.

    #924903
    David
    Staff
    Customer Support

    Awesome – glad to be of help.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.