Show custom field if it exists, and show different elements if it doesn’t

Inside the loop, you can check the custom field with get_post_meta. Like this. If custom field randomname exists then it will show it’s value otherwise it will print <div class=”name”>content</div> <?php if ( get_post_meta( $post->ID, ‘randomname’, true ) ) { echo get_post_meta( $post->ID, ‘randomname’, true ); } else { echo ‘<div class=”name”>content</div>’; } ?> OR … Read more

WordPress Site front End and Back End Loading Slowly

WordPress is a great platform to develop web solutions. However if you consider following points then it would be much better. Reliable DNS Get your wordpress hosting right and use proper caching(WP Super Cache or W3 Total Cache) A clean theme and don’t pile up with lots of plugins Disable trackbacks and pingbacks Move CSS … Read more

Add before_content and after_content to register_sidebar

The limitation is down to the existing arguments and how pretty much all widgets typically output content: echo $args[‘before_widget’]; if ( $title ) { echo $args[‘before_title’] . $title . $args[‘after_title’]; } // Widget content echo $args[‘after_widget’]; Some widgets may offer before/after content hooks, but if you want a “global” fix there’s no surefire way around … Read more

What SQL / WordPress queries would need a nonce?

You might be a little confused as to the purpose and function of nonces in WordPress. Recommended reading: WordPress Nonces An Introduction to WordPress Nonces with Examples Protect_Queries_Against_SQL_Injection_Attacks A nonce is a “number used once” to help protect URLs and forms from certain types of misuse, malicious or otherwise. Nonces help you ensure, somewhat, the … Read more

Ajax form submit within a Post Metabox

Yes you can. Here is a sample code to get you started and some links to follow up. Add a button and a nonce-field to your form <input type=”hidden” name=”my_ajax_nonce” value=”<?php echo wp_create_nonce(‘my_ajax_action’);?>” /> <button id=”submit-my-form” type=”submit”><?php _e(‘Save custom meta data’)?></button> You need to create and register your function you want to execute with your … Read more

Featured image fallback link to permalink

I have updated your code so that the fallback image has post permalink. I hope this helps: if ( has_post_thumbnail() ) { echo ‘<a href=”‘ . get_permalink($post->ID) . ‘” >’; the_post_thumbnail(); echo ‘</a>’; } else { echo ‘<a href=”‘ . get_permalink($post->ID) . ‘” ><img src=”‘. get_stylesheet_directory_uri() . ‘/img/fallback-featured-image.jpg” /></a>’; }

Need to turn this php into WP shortcode

Init your shortcode add_shortcode(‘shortcode_ald_crp’, ‘myshortcode_echo_ald_crp’); The function what you want: function myshortcode_echo_ald_crp() { ob_start(); if ( function_exists( ‘echo_ald_crp’ ) ) echo_ald_crp(); return ob_get_clean(); } you call you shortcode in a post like this: [shortcode_ald_crp] Or into the php code: echo do_shortcode(‘[shortcode_ald_crp]’); UPDATE Change the function add_shortcode shortcode_ald_crp for myshortcode_echo_ald_crp