• I’m using Tweetblender only on a specific page on my blog. Is there a way to insert the TB <script> in html <head> only on this specific page of my blog and not on every page?

Viewing 7 replies - 1 through 7 (of 7 total)
  • This is exactly what I’m trying to do too. Any ideas?

    Have tried placing conditional is_page logic in the plugin code with no luck.

    Plugin Author kirilln

    (@kirilln)

    While custom code could surely work for this, I’d recommend using the Widget Context plugin https://www.ads-software.com/extend/plugins/widget-context/screenshots/ as it seems to be the simplest and most user-friendly solution for this need.

    That’s a cool idea Kirilln. Thanks.

    Just tried it, but it doesn’t suppress the <script> from loading in <head> on every page; it only stops the widget from appearing.

    The issue I’ve got is I’d like to embed tweetblender in one page only, embedded using <form>, and I don’t want <script> loading on every page of my site. Speed’s important; I don’t want any surplus scripts loading on pages when they’re not required.

    So I need a solution to suppress a PLUGIN from being invoked unless required, as opposed to just suppressing a WIDGET. I’ve looked around and haven’t found any obvious solutions.

    Any thoughts? It’s a great plugin – would love to use it – but I can’t accommodate the additional load of the <script> on every page.

    Plugin Author kirilln

    (@kirilln)

    Ah, I see now. The script loads on every user-facing page because there is ability to embed the widget straight into the content of a post or page using the <form> notation. Since it’s expensive to parse every page for the <form> tag I opted out to load the script and CSS on every page just in case.

    To help in your situation, you’ll need to edit file wp-content/plugins/tweet-blender/tweet-blender.php and change this code on line 194:

    function tb_load_js() {

    $dependencies = array('jquery');
    $tb_o = get_option('tweet-blender');
    // load PHPDate only if have a custom date
    if ($tb_o['general_timestamp_format'] != '') {
    wp_enqueue_script('phpdate', '/' . PLUGINDIR . '/tweet-blender/js/jquery.phpdate.js', array('jquery'));
    $dependencies[] = 'phpdate';
    }
    // load JSON plugin only if caching is enabled
    if ($tb_o['advanced_disable_cache'] != 'on') {
    wp_enqueue_script('tojson', '/' . PLUGINDIR . '/tweet-blender/js/jquery.json-2.2.min.js', array('jquery'));
    $dependencies[] = 'tojson';
    }
    // load main JS code
    wp_enqueue_script('tbmain', '/' . PLUGINDIR . '/tweet-blender/js/main.min.js', $dependencies);
    }

    to something like this:


    function tb_load_js() {

    if ($post->ID != XXXX) {
    return;
    }

    $dependencies = array('jquery');
    $tb_o = get_option('tweet-blender');
    // load PHPDate only if have a custom date
    if ($tb_o['general_timestamp_format'] != '') {
    wp_enqueue_script('phpdate', '/' . PLUGINDIR . '/tweet-blender/js/jquery.phpdate.js', array('jquery'));
    $dependencies[] = 'phpdate';
    }
    // load JSON plugin only if caching is enabled
    if ($tb_o['advanced_disable_cache'] != 'on') {
    wp_enqueue_script('tojson', '/' . PLUGINDIR . '/tweet-blender/js/jquery.json-2.2.min.js', array('jquery'));
    $dependencies[] = 'tojson';
    }
    // load main JS code
    wp_enqueue_script('tbmain', '/' . PLUGINDIR . '/tweet-blender/js/main.min.js', $dependencies);
    }

    Ahhhh I see – genius! Thank you Kirill. That’s a perfect solution.

    hadebe – this should work for you too.

    Thread Starter hadebe

    (@hadebe)

    Thanks a lot.

    Thread Starter hadebe

    (@hadebe)

    I also had to opt out the following functions:

    tb_add_header_config()
    tb_add_header_css()

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Tweet Blender] on every page?’ is closed to new replies.