@taijj, Apparently the tool bypasses the normal WordPress hooks. An example of an integration we have for such a situation is the Content Views plugin:
function cmplz_content_views_cookieblocker($html){
return COMPLIANZ::$cookie_blocker->replace_tags($html);
}
add_filter( 'pt_cv_view_html', 'cmplz_content_views_cookieblocker' );
We need a filter like the pt_cv_view_html filter. If it filters the outputted ajax loaded html, this will block the content.
In addition you need to enabled “block ajax loaded content” in the general settings. Which sets the placeholders on ajax load.
What plugin do you use for this?
Thread Starter
taijj
(@taijj)
Hi @rogierlankhorst ,
Thanks for the reply! I’m not using any plugin. I wrote the script, that uses ajax, myself and it’s part of my custom theme. If you get the impression that WordPress stuff is bypassed… that’s probably because it is.
I’m not an experienced WordPress Dev, and made something like this for the first time.
Here’s what I’m doing with ajax:
Javascript
function loadContent(id)
{
var data = { action: "tnet_load_post_content", pageId: id };
useAjax(data, onContentLoaded); // Ajax call
}
function onContentLoaded(response)
{
var data = JSON.parse(response); // parse response
contentContainer.html(data[0]); // Add parsed html to dedicated container
// Do more stuff that WordPress does by default, but not for
// HTML that was loaded in later with ajax
addMissingStyles(data[1]);
addMissingScripts();
addProjectListeners();
updateTabs();
updateLanguageButtons();
updateBackButtons();
scrollToTop();
}
php
//Load page into another page
add_action( 'wp_ajax_tnet_load_post_content', 'tnet_load_post_content' );
add_action( 'wp_ajax_nopriv_tnet_load_post_content', 'tnet_load_post_content' );
function tnet_load_post_content() {
$id = $_POST['pageId'];
$meta = get_post_meta( $id, 'panels_data', true );
if( class_exists( 'SiteOrigin_Panels' ) && $meta )
{
$renderer = SiteOrigin_Panels::renderer();
$content = $renderer->render( $id );
$css = $renderer->generate_css( $id );
}
else
{
$css = '';
$content = apply_filters( 'the_content', get_page($id)->post_content );
}
echo json_encode(array($content, $css));
die(); //<- will add a 0 in response, if not called!
}
If you got the time or need more details, I’ve even written a post about this topic here
Any help would be greatly appreciated!
Regards,
T
-
This reply was modified 3 years, 6 months ago by
taijj.
Hi @taijj,
If you add something like this within the code:
$content = COMPLIANZ::$cookie_blocker->replace_tags($content);
It should work.
Thread Starter
taijj
(@taijj)
Thank you @rogierlankhorst, that is exactly what I needed! Works like a charm! 🙂
You’re awesome! Thank you!
Regards,
T
-
This reply was modified 3 years, 6 months ago by
taijj.