Stripping URLs & Email from post submissions

You can use the_content (Click here for more info) hook to change the content while rendering the post/page. This will be triggered when Post is being read from Database. So post content will not be changed in database but only filtered while rendering. add_filter( ‘the_content’, ‘remove_email_and_url_from_post’ ); function remove_email_and_url_from_post( $content ) { // Check if … Read more

Add/remove CRON action depending on variable

I am not sure why the remove_action isn’t working because by the looks of your code, it should. Alternatively, you can add the conditional logic to your generate_sitemap() function generate_sitemap() { global $create_sitemap; if ( $create_sitemap ) return false; $sitemap = ‘<?xml version=”1.0″ encoding=”UTF-8″?>’; $sitemap .= ‘<urlset xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9″>’; // Get a query of all jobs … Read more

Rewrite rule and display of post

I don’t understand why but the regex seemed to be the last issue. It was catching it but even with the post name hardcoded in it didn’t work correctly. This is the final working version. add_filter( ‘post_link’, ‘custom_permalink’, 10, 3 ); add_filter(‘rewrite_rules_array’,’wp_insertMyRewriteRules’); add_filter(‘init’,’flushRules’); function custom_permalink( $permalink, $post, $leavename ) { $category = get_the_category($post->ID); if ( … Read more

Create a pre-filtered version of the Media Library

Thanks to Milo for the pointer. I’m going to have to work on my application, but the main point is this filters the media library as required. function only_licensed_images($query){ global $pagenow; if( ! in_array( $pagenow, array( ‘upload.php’, ‘admin-ajax.php’ ) ) ) return; $query->set( ‘attachment_category’, ‘Licensed Stock Images’ ); } add_action(‘pre_get_posts’,’only_licensed_images’);

Error using wp_mail inside custom function

That’s because you have put function tps_set_html_email_content_type inside the tps_send_email, and each time you call it, it will declare the tps_set_html_email_content_type function again. Just move it out: function tps_set_html_email_content_type() { return ‘text/html’; } function tps_send_email($emailTo, $subject, $content) { add_filter( ‘wp_mail_content_type’, ‘tps_set_html_email_content_type’ ); //Send the email $mailSent = wp_mail($emailTo, $subject, $content); //Reset HTML content type back … Read more

get_posts() interrupt because of filter

Check that the current query is the main query using $query->is_main_query(). add_action( ‘pre_get_posts’, array($this, ‘exclude_category’) ); public function exclude_category( $query){ if( is_admin() && $query->is_main_query() && isset( $_GET[‘cta_filter’]) && ! empty( $_GET[‘cta_filter’] ) ) { $term = sanitize_text_field( $_GET[‘cta_filter’] ); $tax_query = $query->get(‘tax_query’) ?: array(); $tax_query[] = array( ‘taxonomy’ => ‘cta_tax’, ‘field’ => ‘slug’, ‘terms’ => … Read more

WordPress removing slashes from shortcode output

Here is the correct shortcode function function section_shortcode_func( $atts, $content = null ){ $atts = shortcode_atts( array( ‘bgimage’ => ” ), $atts); $bgimage = isset( $atts[‘bgimage’] ) ? $atts[‘bgimage’] : ”; ob_start(); echo “<div class=”section” style=”background-image: url($bgimage)”>”; return ob_get_clean(); } Now you can call it this way [section bgimage=”xxx.xxx/wp-content/uploads/2017/10/xxx.jpg”]

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