Jetpack Related Posts Function

Hi there,

I’m trying to include a function in my theme’s extras.php that removes the default position of Jetpack Related Posts.

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_filter('wp', __NAMESPACE__ . '\\jetpackme_remove_rp', 20);

That is the function I’m trying to use, based on some quick research I have ignored the NAMESPACE for the class_exists call, however I am getting a Fatal Error when I try to access the site.

Is there a way I can also ignore the NAMESPACE for this line: $jprp = Jetpack_RelatedPosts::init(); ?

Many thanks.

Solved.

A backslash in:

$jprp = \Jetpack_RelatedPosts::init();

was all I needed.

:blush:

2 Likes