preg_match() not working with post content

In your code, $content does not exist. You need to accept the argument into your function: function find_my_image( $content ) { if ( is_single() ) { if ( preg_match( ‘/(<img[^>]+>)/i’, $content, $result ) ) { $content .= ‘<p>Image has been found</p>’; } else { $content .= ‘<p>Sorry, no image here!</p>’; } } return $content; } … Read more

How to stop filter from running on the index.php page?

You need to return content from filter function. function find_my_image( $content ) { if( is_single() ) { if ( preg_match(‘#(<img.*?>)#’, $content, $result ) ){ $content .= ‘<p>Image has been found</p>’; } else{ $content .= ‘<p>Sorry, no image here!</p>’; } } return $content; } add_filter( ‘the_content’, ‘find_my_image’ );

WordPress overwrites UNC

You could attempt to alter the allowed protocols. function wp_allowed_protocols_unc_wpse_100080($protocols) { return $protocols + array(‘file’); } add_filter(‘kses_allowed_protocols’,’wp_allowed_protocols_unc_wpse_100080′); And add links of the form file://///path/to/file.txt— see https://stackoverflow.com/questions/1369147/linking-a-unc-network-drive-on-an-html-page I do not know if that will work. That need for five slashes could be an issue. You could also create a shortcode. function unc_link_wpse_100078($atts,$content) { return ‘<a href=”https://wordpress.stackexchange.com/questions/100080/file://///”.$content.'”>’.$content.'</a>’; … Read more

Shortcode / plugin with custom (flexible) output

The first problem you didn’t even mention is: you are putting shortcodes into a theme. Shortcodes are pure plugin territory, because they are changing post content and must survive a theme switch. Once you fixed that and moved the shortcodes to a plugin named inferno_shortcodes, the rest is easy: In your plugin ask for theme … Read more

Filter causing loss of _wp_attachment_metadata

Given that that is a filter, it should be returning $metadata instead of returning nothing. add_filter( ‘wp_generate_attachment_metadata’, ‘mvt_save_photo_credit’, 10, 2 ); function mvt_save_photo_credit( $metadata, $attachment_id ) { add_post_meta($attachment_id, ‘_mvt_credit’, $metadata[‘image_meta’][‘credit’], true); return $metadata; // <– giving back what we got } I was able to duplicate the issue you describe, and that small change fixed … Read more

an action hook when a post reaches a certain number of views

Use the action from update_post_meta(): do_action( “updated_{$meta_type}_meta”, // example: updated_post_meta $meta_id, $object_id, // post ID $meta_key, // ‘view’ $_meta_value // view count ); Something like this should work (not tested): add_action( ‘update_post_meta’, ‘badge_check’, 10, 4 ); function badge_check( $meta_id, $post_id, $key, $value ) { if ( ‘views’ !== $key or 1000 > $value ) return; … Read more

How does wordpress add ‘style’ attribute to element

WordPress of course does nothing so it might be a plugin do this, or a custom theme function. How does this happen? The plugin may use the_content filter to find all “” element and inject content. Or it can be a visualize text editor with JavaScript code that modify content itself without applying a filter. … Read more

What are the steps + prerequisites for using an add_filter?

I like to think of add_filter as a way for you to adjust a variable. It can be used anywhere you see an apply_filters in the code. Typically, you return a variable value instead of echoing it out. Your example would be better written like so: function remove_footer_admin () { return ‘Fueled by <a href=”http://www.wordpress.org” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)