Functions in custom theme

Using functions.php Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.) In that way, the functions.php of a child theme provides a smart, trouble-free method of modifying the functionality … Read more

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

Warning: : DOMDocument::loadHTML(): Empty string supplied as input in functions.php when adding classes to post images

Here’s an updated version of the code that will avoid the warning by adding a simple check that will return $content unmodified if it’s an empty string. The original code adds <html> to the modified markup (check the page source), which we don’t want. The code below fixes that too. add_filter( ‘the_content’, ‘wpse_add_img_post_class’ ); function … Read more