Automatically insert php function into post $the_content

I’m sure you want to use the_content filter instead of the default_content filter (already mentioned by @jgraup) because what happens if the generated HTML changes? Then you’re stuck with it in your content. It’s better to add it dynamically. Here’s one suggestion: add_filter( ‘the_content’, function( $content) { if( ! in_the_loop() ) return $content; if( ‘property’ … Read more

Checked() showing up twice in custom fields

checked() will echo the result by default. That’s the problem. To concat, you need to disable echo functionality by specify third param to false: echo ‘<input type=”checkbox” id=”my_meta_box_check1″ name=”my_meta_box_check1″ ‘ . checked( $check, “on”, false ) . ‘/>’;

Validate a users email address when using gmail to register

Hmm, should try harder before asking for help 🙂 Was quite simple in the end (right or wrong) it works: $domain_array = array(‘googlemail.com’,’gmail.com’); $validemail = is_email($email_to_check); $exists_text=””; if ($validemail): $exists = email_exists($email_to_check); list($user, $domain) = explode(‘@’, $email_to_check); if (!$exists): if (strpos($user, ‘+’)) { list($username_email, $crap) = explode(‘+’, $user); $exists = email_exists($username_email . ‘@’ . $domain); … Read more

Hide the Private prefix on one specific page

This worked for me. One of the keys is that you have to make sure to pass the content through unchanged if it doesn’t meet the condition. function title_format($content) { if (is_page(‘members’)) : return ‘%s’; else : return $content; endif; } add_filter(‘private_title_format’, ‘title_format’); add_filter(‘protected_title_format’, ‘title_format’); This will only apply to the page with a slug … Read more

Overriding a theme redux file in child theme

If you need to add the settings in parent theme created section, just place the below code in child functions.php But remember to replace OPT Name with your_opt_name in “OPT_NAME”.(To find OPT Name just open /parent-theme/includes/options/options-config.php and in top there’s a line $opt_name=”your_opt_name“; ) function add_product_description($sections){ $sections[10][‘fields’][] = array( ‘id’ => ‘product_extra_description’, ‘type’ => ‘multi_text’, … Read more

How to add a column to the Trash page?

You can check the value of the post_status query variable and make sure that it’s set to trash: function wpse239286_trash_column( $columns ) { // Bail if we’re not looking at trash. $status = get_query_var( ‘post_status’ ); if ( ‘trash’ !== $status ) { return $columns; } return array_merge( $columns, array( ‘trash_column’ => __( ‘Trash Column’, … Read more

Automatically Add Specified Value to Attachment Metadata upon Upload

You’re close! Try using these hooks instead. // Add post meta to new audio uploads. function auto_update_audio_meta( $post_ID ) { if ( wp_attachment_is( ‘audio’, $post_ID ) ) { add_post_meta( $post_ID, ‘artist’, ‘test’ ); } } add_action( ‘add_attachment’, ‘auto_update_audio_meta’ ); For attachment updates // Update post meta to updated audio uploads. function auto_update_audio_meta( $post_ID, $post_after, $post_before … Read more

Custom excerpt legnths for specific pages

The excerpt length is the number of words, not the characters. Assuming that every word is 8 characters long in average, you might want to use this: function wpdocs_custom_excerpt_length( $length ) { if( is_front_page() ){ return 50; } else { return 100; } } add_filter( ‘excerpt_length’, ‘wpdocs_custom_excerpt_length’, 999 ); Source : WordPress codex

Restrict WordPress File Type Uploads by User Type

There is a syntax error in your conditional: current_user_can(‘administrator’) The input value is wrapped in ‘ ’, which should be wrapped in ‘ ‘ instead. Right now, because ‘administrator’ is neither a role nor capability, the above will always return a false value, therefore if(!current_user_can(‘administrator’)) will always return true, which will restrict the mime type … Read more