Excerpt issues

Very simply to explain: Event+ ignores the <!-- more --> tag.

Apparently it also ignores post shortcodes.

    Arun Basil Lal
    • 2
    • #26,142

    Hey sciamannikoo,

    Here is what I did. The developer confirmed that the plugin wasn't doing anything to strip off More tags or shortcodes.

    Then I went ahead and tested it out with CustomPress shortcodes, and it works well. No problems here for me.

    Where did the more tag come in to play? The events archives doesn't show any text anyway, but I might be wrong.

    Which theme are you using? Can you try it with the default theme, twenty ten? (You do not have to switch themes, go to appearance and right click the preview and open in a new page)

    You can edit the url on the preview to see the preview of any specific page. makes sense? Activating themes can make you loose some widgets sometimes.

    Also note that, themes in general strip off shortcodes from the archive views, so that could be a reason for the shortcodes not showing up, but you should see them on the event listing.

    Let me know!

    sciamannikoo

    I've forgot to mention that the problem is in the Upcoming Events widget in the front page.

    Trying a Twenty Eleven or Twenty Ten preview, I can't see the widget in the preview.

    I'm using HeadWay 3.1.2 theme.

    Arun Basil Lal
    • 2
    • #26,142

    Now am confused, sorry. Are you saying that the more tag and the short codes aren't working on the widget? More tag isn't supposed to work in the widget and of course, short codes would be stripped off.

    Please advice.

    sciamannikoo

    Yes, that's what I'm saying.

    It's fine if shortcodes are stripped away, but I simply can't show in the widget the whole event's text. This would makes the page full of unneeded text. The widget must show the event dates, the title and possibly an excerpt of the event's content (using the more tag or the non existent excerpt field).

    Please take a look to how the front page looks with just one event: http://dev.tamtando.com/

    I've just noticed another issue.
    The date div (class="wpmudevevents-date") is supposed to show the calendar icon. For some reason this icon appears only in the single page of the event (here: http://dev.tamtando.com/eventi/2012/04/la-sfom-e-i-corsi-suzuki-aprono-le-ammissioni/)

    Last think... please ignore the styling: this is am under developing site ;)

    sciamannikoo

    Any update about these issues?

    Just to recap, there are two main problems:

    1. Event's post content in the widget needs to be truncated
    Currently when using the upcoming events widget, the list of events contains the whole event's post content. This makes the widget mostly useless when used in a sidebar.
    See here: http://dev.tamtando.com/ (the sidebar to the left)

    As stated by Arun, "More tag isn't supposed to work in the widget and of course, short codes would be stripped off", however, it shouldn't be hard to make the plugin handle them (the first with a call to the stripos() function and the second with a call to the do_shortcode($content) function).

    Also an excerpt field would be handy, making the plugin work like with we are used with normal posts (use the excerpt, if available, otherwise get the post content, run do_shortcode($whatever), get the string until the <!-- more --> tag or use the whole string).

    2. Styling is not consistent between different pages
    Compare the widget in this page with the very same widget in this page.
    The event date div in the first page doesn't contain the calendar icon, whilst the one in the second page has the icon.
    Inspecting the styling, is see that the second page load a css file called "front.css", that contains the needed styling, but the first page doesn't load the this file.

    Hakan

    Hi sciamannikoo,

    1. Truncation of text and running of the shortcodes inside the widgets (like most other appearance settings) are not determined by the plugin, but by your theme. It seems that your theme does not support it by default. You can add this functionality by simply adding these lines to the functions.php of your theme:

    // Will let shortcodes run inside the widget
    add_filter('widget_text', 'do_shortcode', 10);
    // Call a function to truncate the text
    add_filter('widget_text','tamtando_truncate_widget_text', 11);
    function tamtando_truncate_widget_text( $text ) {
    // Replace 20 with how many words you want
    return wp_trim_words( $text, 20  );
    }

    Please note the 10 and 11 (priority) numbers. In the above example it will run the shortcode first and then truncate the result. If you want the opposite of it, just reverse the numbers (Function having a lower priority number is executed first).

    2. The second one is a bit more complicated, but it is again definitely not a bug. We, as developers, are always considering loading css and javascript files only when they are necessary, for optimization reasons. But as a side effect of this, some pages that are in need of those files may be missed. Unfortunately there is a weakness in WP so that you cannot look at the page and see if it does have a widget and related style file should be loaded. Css file for this widget is only loaded when it is an Events page, not for your home page. The remedy for this is again including some simple codes inside functions.php:

    // Call a function to load the css file
    add_action( 'template_redirect', 'tamtando_load_style' );
    function tamtando_load_style() {
    // This will load the css file for home page. If you have other pages, remove this line.
    if (is_home() )
    wp_enqueue_style('eab_front');
    }

    If you need further help, please let me know.

    Cheers
    Hakan

    sciamannikoo

    Hakan, thank you for your very useful answer!

    About the first solution, it makes sense. However it seems that I'm not hooking the filter at the right moment.

    Right now I'm calling the filter inside "init" action, but I don't see any change (neither an error, even with WP debug mode enabled). It seems that the filter is simply ignored.

    This is my implementation of your advise:

    function tamtando_truncate_widget_text($content) {
    	//Parse shortcodes
    	$content = do_shortcode($content);
    	//Trim the content
    	$content = wp_trim_words($content, 20);
    	return $content;
    }
    add_filter('widget_text', 'tamtando_truncate_widget_text', 10, 1);

    As you can see, instead of defining two filters, I've preferred to define a single filter that takes care of shortcodes and content's trimming. But I don't think there is anything wrong there.

    About the second solution, it simply works ;) thanks!

    Hakan

    Hi sciamannikoo,

    I am not sure do_shortcode function will work like that. Normally it is used inside the templates, i.e. when there is a content available. However during 'init' there is no content yet.

    Did you already try my solution?

    Cheers,
    Hakan

    sciamannikoo

    I wasn't clear Hakan.

    What I did is indeed your solution.

    That's roughly what I've done.

    In my functions.php:

    [...]
    add_action('init', 'myInit');
    function myInit() {
    	add_filter('widget_text', 'tamtando_truncate_widget_text', 11, 1);
    }
    
    function tamtando_truncate_widget_text($content) {
    	if (!is_admin()) {
    		//Parse shortcodes
    		$content = do_shortcode($content);
    		//Remove shortcodes leftovers
    		$content = strip_shortcodes($content);
    		//Trim the content
    		$content = wp_trim_words($content, 10);
    		$content = '***' . $content;
    	}
    	return $content;
    }
    [...]
    Hakan

    Hi sciamannikoo,

    Your codes seem right, but I suggest you to remove add_filter outside init action. Filters are already actions; they know when they should run, unless you want to delay them after a certain action. In your case this is redundant.

    Can you try to change 10 by a higher number? Maybe there are some html codes which will be counted as words.

    If these don't work, I will insist that you try my initial suggestion.

    Cheers,
    Hakan

    sciamannikoo

    Hakan, I've tried using a very hig priority, but this doesn't help.

    However I have to make some clarification on how I'm implementing this.

    All code customizations (mostly custom filters, actions and shortcodes) are handled by a plugin.

    So, first of all, when I've mentioned the functions.php, I was wrong.
    I prefer a plugin, so I'm not bound to the current theme I'm using.

    The code therefore is inside the plugin.
    This plugin is a class.
    This class, in the construction, calls add_action("init", array(&$this, "myplugin_init"));
    Inside the myplugin_init() I handle all my hooks.

    This should explain why I've slightly changed you initial suggestion to my implementation.
    Actually the only change is the call to add_filter('widget_text', 'tamtando_truncate_widget_text', 11, 1); inside my init function, that is called by the init action of the plugin.

    I could indeed add the filter outside my plugin class, but honestly this doesn't look very clean to me.

    It seems that, as you've said, 'init' is not the right "moment" to add this filter.
    So what I can do is use an action different than "init", but I don't know which one I could use.

    Hakan

    Hi sciamannikoo,

    Sorry my mistake that I didn't clarify that "10". I meant this one:

    $content = wp_trim_words($content, 10);

    What I suspect is truncating is working, but you cannot see it as the left 10 words does not produce any output that can be noticed.

    FYI, functions.php of your theme is loaded exactly as it is like a plugin. So instead of customizing a plugin, editing functions.php is preferable, because plugins are updated frequently, but themes are not. So there is less risk that your custom codes are overwritten.

    But if it is a custom plugin which will not update forever, you can forget the above paragraph :)

    Cheers
    Hakan

    sciamannikoo

    Hakan,

    $content = wp_trim_words($content, 10); - I tried already, but any number in there, doesn't change anything.
    Actually it seems that the whole filter is ignored (see at the end of this post), as I've also forced some hard-coded string in the content that I don't see it:

    function tamtando_truncate_widget_text($content) {
    	if (!is_admin()) {
    		//Parse shortcodes
    		$content = do_shortcode($content);
    		//Remove shortcodes leftovers
    		$content = strip_shortcodes($content);
    		//Trim the content
    		$content = wp_trim_words($content, 30);
    		<strong>$content = '<strong>***</strong>' . $content;</strong>
    	}
    	return $content;
    }

    About functions.php vs plugin: I still can't explain myself as good as I want :)
    This plugin is a custom made plugin, it's there for my own needs.
    A theme's function.php is too strictly bound to the theme itself. If I want to reuse my plugin in another website, regardless the used theme, I can use it.
    Instead, having it in the functions.php, I would be bound to the theme itself (either is a third-party theme, a child theme or a complete custom theme).

    About the filter being ignored, I've just realized that it actually works on other widgets (see in the horizontal menu, the last item "Contatti": it is a 3 columns widget and the first one is actually handled by my filter: it has the "***" at the beginning).

    So, for some reason, the Upcoming Events widget is working differently. I must perhaps hook to a different filter?

    Hakan

    Hi sciamannikoo,

    Sorry that I have just noticed that excerpts are intentionally disabled by the developer, which I was not expecting. If it is there, certainly there is a reason for that. But for the time being, you can try to remove this line from lib/widgets/Popular_Widget.class.php

    'excerpt' => false,

    I will ask the reasoning to the developer.

    Cheers
    Hakan

    sciamannikoo

    No no Hakan, please, let's forget for a moment about the excerpt :)

    The excerpt stuff was just a proposal: I know that is disabled by the plugin right now.

    What I'm trying to do is to work with the actual content of the event and everything you suggested is supposed to work with it, but the plugin, or the widget, seems to ignore bypass the default filter.

    So let's stick with the suggestions you gave me.

    If the developer will ever consider adding the excerpt, I wouldn't even need all this customization.

    Hakan

    Then it will be a feature request :)

    Can I ask you to open a new topic for that so that I can close this crowded one :)

    Cheers
    Hakan

    sciamannikoo

    ok. Indeed, this post got very confused :)

    I'll consider this post a feature request (that will be reflected in UserVoice).

    The new post will be about how to filter the widget's content, until the feature will be implemented.

    Thanks again Hakan.

    Hakan

    I read your article.

    Yes, Events+ as you know is a very fresh plugin, but it has a core such that it can be incredibly extended, so it is very promising. In the new future you will hear very much improvements about it.

    Take care
    Hakan

JOIN 378558 HAPPY MEMBERS

We pride ourselves on our level of customer support and responsiveness to member requests. Your WordPress experience will never be the same


Become a member

  • PayPal Partner