WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] Change character count of excerpt (8 posts)

  1. pszalk
    Member
    Posted 1 year ago #

    Is it possible to shorten the number of characters in email excerpts of posts using Subscribe2? It seems one can only choose to send excerpt or full post.
    Thanks,
    Peter

    http://wordpress.org/extend/plugins/subscribe2/

  2. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @Peter,

    It is certainly possible but requesres a little bit of code editing.

    In the subscribe2 folder in your wp-content/plugins folder you'll find the plugin files. You need to look in the classes folder for class-s2-core.php. Edit this file and towards the very bottom of the file you'll find this line:

    var $excerpt_length = 55;

    Change this number to a lower one for a shorter excrept and a larger number for a longer excerpt.

  3. Inndesign
    Member
    Posted 1 year ago #

    Hello Mattyrob. Every time we update the plugin in a blog, I have to manually change the excerpt length variable on every blog installed. On next update, could you PLEASE create a user definable entry on the Settings > Email Settings page that stores the value in the SQL? I know that is a simple add whereas I develop in Zend PHP. Thanks.

  4. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @Inndesign,

    There is a filter in the code from version 8.8 onwards that allows this to be done with a little piece of code thus removing the need to edit the code after each update. Something like this:

    function my_excerpt() {
    	// return whatever number of words you want the excerpt length to be
    	return 30;
    }
    add_filter('s2_excerpt_length', 'my_excerpt');
  5. Inndesign
    Member
    Posted 1 year ago #

    Thanks Matthew. I searched quite a bit and didn't find that snippet of code in class-s2-core.php in discussion above or any other associated file. Thanks.

  6. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @Inndesign,

    Sorry, it seems I wasn't particularly clear. The code above isn't in Subscribe2. It is supposed to be used in a new plugin in WordPress that will alter the functioning of Subscribe2. Doing it this way means your changes are preserved when the plugin is upgraded.

  7. Inndesign
    Member
    Posted 1 year ago #

    Okay, so we are getting there inch by inch. Could you be a little more detailed and a lot less abstract? I am using WordPress 3.5.1. I think you are saying to paste code as provided above directly into a custom code window in what new plugin? I know there are several variants of plugins that allow a person to paste in snippets of code that overrides the base code, retained even if a plugin or theme is updated.

    The variable being what? Change the "30" in the above code to any value? It would seem my suggestion above for an added user definable option in Settings > Email Settings would be a far cry easier than wading through encrypted methods that a normal user would have no idea how to implement.

    Personally, I can't apply anything you have shared to this point for lack of explanation and definition.

  8. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @Inndesign,

    My apologies if I have pitched my responses to you are too high a level but I thought you might understand since you say your are a developer in Zend PHP.

    WordPress employs an API system of hooks called actions and filters that allow for the huge array of plugin that are available to add and change functionality. Instead of presenting new users with a huge and daunting array of options I try to keep the admin areas as clean as possible and also code into the plugin an API so plugins for Subscribe2 can be written to alter or extend the default behaviour.

    So, what I was suggesting above was that you write a plugin from scratch to apply a filter to the Subscribe2 API in order to change the excerpt length.

    There is much more information about writing a WordPress plugin here but to summarise, all you need to do is create a php file (the opening and closing PHP tags, insert a WordPress plugin header block (see the codex page) and then paste in the code above.

    The current excerpt length is '55', the code snippet about changes that to 30, you can feel free to change the number to whatever you like.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.