Filter oembeds tags to modify iframe attributes

I was able to solve the the CORS issue by using this snippet which now allows this iFrame to allow-same-origin or runs scripts inside this domain. function oembed_iframe_overrides($html, $url, $attr) { if ( strpos( $html, “<iframe” ) !== false ) { return str_replace(‘<iframe class=”wp-embedded-content” sandbox=”allow-scripts allow-same-origin”‘, ‘<iframe class=”wp-embedded-content” sandbox’, $html); } else { return $html; … Read more

Can’t change a label in woocommerce with the normal filter

You have to use the woocommerce_default_address_fields hook: add_filter( ‘woocommerce_default_address_fields’ , ‘wpse_120741_wc_def_state_label’ ); function wpse_120741_wc_def_state_label( $address_fields ) { $address_fields[‘state’][‘label’] = ‘County’; return $address_fields; } This (and more) is described at the woocommerce docs: Customizing checkout fields using actions and filters, so read your stuff next time thoroughly… 😉 Edit: Above code isn’t working for all cases, … Read more

Problem getting single_template filter to work – I want to serve a different single.php file for posts in a certain category

The problem was that the remove_filter function wasn’t working. Apparently this is not uncommon from what I’ve read. I tried testing it with different priorities (1, 9, 20, 999), but there was no difference. So my filter in the child theme and the filter I was trying to remove from the parent theme both had … Read more

Setting title using wp_title filter

Since wp_title() is usually called from the header.php file of your theme, then it runs on every page of your WordPress (frontend usually). So place the filter hook and function in your theme’s functions.php file, and just check if it’s a blog post before you change the title. Something like this: add_filter(‘wp_title’, ‘filter_pagetitle’); function filter_pagetitle($title) … Read more

Customise Jetpack Publicize text

Just some general remarks: Why isn’t the following change working? $custom_message = get_the_title( $post->ID ) .”. $hash_tags; to: $custom_message = get_the_content( $post->ID ) .’ ‘. $hash_tags; Note that get_the_content() doesn’t take a post ID as an input parameter and it depends on global variables, like $pages that’s derived from $post->post_content (with some pagination adjustments), within … Read more

How can I reliably and globally disable wptexturize?

Plugins will be able to re-enable any filter you have switched off, if they do so after you are finished. So the trick is to make sure you are the last one to do something with this filter by setting a high number, low priority on it. add_filter( ‘run_wptexturize’, ‘__return_false’, 9999 );

get_the_excerpt() with fallback like the_excerpt()

The function the_excerpt() is only a echo of the function get_the_excerpt(): function the_excerpt() { echo apply_filters(‘the_excerpt’, get_the_excerpt()); } If you like a fall back for no input the excerpt meta box, then create a text from the content – get_the_content(). You can use the core function wp_trim_words() for set the counter for words and easy … Read more

Add ‘if exists’ to filter

You want has_post_thumbnail. add_filter( ‘the_content’, insert_featured_image, 20 ); function insert_featured_image( $content ) { global $post; if (has_post_thumbnail($post->ID)) { $content = preg_replace( “/<\/p>/”, “</p>” . get_the_post_thumbnail($post->ID, ‘post-single’), $content, 1 ); } return $content; } Note: The code above is from the post referenced in the OP, but with the has_post_thumbnail conditional. I also had to add … Read more