Limit length of first excerpt in the loop

To determine where you are inside the loop in this filter, you will have to access the global main query. Like this: add_filter (‘excerpt_length’, ‘wpse268679_custom_excerpt_length’); function wpse268679_custom_excerpt_length ($length) { // access main query global $wp_query; // do this only for the main loop and the first post in the query if (is_main_query() && ($wp_query->current_post == … Read more

Remove stylesheets from Campaign Monitor plugin

The string for the handle is custom_cm_monitor_css but it is passed to Helper::tokenize() which turns it into forms-for-campaign-monitor-custom_cm_monitor_css. Note that the ID of the stylesheet in the page source shows forms-for-campaign-monitor-custom_cm_monitor_css-css but the ending -css is appended by WordPress. So, we need to dequeue the style with the handle: forms-for-campaign-monitor-custom_cm_monitor_css This needs to happen later … Read more

How to create a php variable using WordPress the_title() function

Indeed, the the_title function echoes the title, unless you set the third parameter to false (default true). So you start with this; $title = the_title (”,”,false); Now, $title may contain all kinds of characters that cannot be used in PHP variable names, so we need some sanitization: $title = preg_replace(‘/[^A-Za-z0-9\_]/’, ”, $title); // Removes special … Read more