WordPress.org

Ready to get started?Download WordPress

Forums

Hack AddThis plugin to place button outside the_content (7 posts)

  1. mpmchugh
    Member
    Posted 5 years ago #

    Is it possible to edit the plugin code so the button the AddThis plugin places on the page is not inside the "storycontent" div, but outside it?

    They are using this line, I believe to place the plugin output:

    add_filter('the_content', array(&$this, 'social_widget'));

    Is there a way to edit this line, so it drops its div elsewhere? perhaps into a custom field?

    Thanks,
    mpm

  2. Michael Fields
    Themer
    Posted 5 years ago #

    You'll have to hack the plugin file. Comment out the line that has:

    add_filter('the_content', array(&$this, 'social_widget'));

    Then create a wrapper function for social_widget()

    public function print_social_widget( ){
        print $this->social_widget( '' );
    }

    Add a new custom action which will call our wrapper function, this can be placed below the line that we commented out before.

    add_action( 'custom_social_widget', array(&$this, 'print_social_widget'));

    Now go to your template and add the following code to your template files where you would like the button displayed:

    <?php do_action( 'custom_social_widget' ); ?>

    Let me know how this works for you.

  3. mpmchugh
    Member
    Posted 5 years ago #

    Thanks! That worked perfectly.
    -mpm

  4. Michael Fields
    Themer
    Posted 5 years ago #

    No problem!

  5. mpmchugh
    Member
    Posted 5 years ago #

    Thanks again, but I've run into an odd wrinkle, which is that, though the AddThis button shows up fine for the entries on the main, unfiltered Blog page and on individual blog entries, it disappears when you click on a category link to filter the blog page down to a single category. Any idea why that might be happening?

    Thanks,
    Michael

  6. Michael Fields
    Themer
    Posted 5 years ago #

    your theme most likely has a category.php or archives.php file in it. you will want to add the same code <?php do_action( 'custom_social_widget' ); ?> to the loop in these files too.

  7. mpmchugh
    Member
    Posted 5 years ago #

    Hmm... this hack no longer works in the new addthis plugin, as they seem to have restructured it a bit when adding a sidebar option.

    The string in question has been changed to:

    add_filter('the_content', 'addthis_social_widget');

    Any suggestions on how to adapt?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.