get_the_excerpt() not returning anything when post has no excerpt

Double check that you don’t have a check for has_excerpt() that’s hiding the “auto-generated” excerpt. Even if get_the_excerpt() returns something made from post_content, has_excerpt() still returns false if the excerpt is empty. If that’s not the case, see if there’s a function that filters on get_the_excerpt that could be effecting this. To answer your question, … Read more

Adding Google Analytics to footer selectively

You have the ?> and ?php at wrong place, this way user logged in testing is a simple text. Try this: // add google analytics to footer function add_google_analytics() { if ( !is_user_logged_in() ) { ?> <!–Google Analytics–> <script type=”text/javascript”> var _gaq = _gaq || []; _gaq.push([‘_setAccount’, ‘UA-XXXXXXXX-X’]); _gaq.push([‘_trackPageview’]); _gaq.push([‘_trackPageLoadTime’]); (function() { var ga = … Read more

How to add an admin function only to posts, not pages?

You can use post type conditional tag: if ( ‘post’ == get_post_type() ) Complete: function excerpt_count_js(){ if ( ‘post’ == get_post_type() ) { echo ‘<script>jQuery(document).ready(function(){ jQuery(“#postexcerpt .handlediv”).after(“<div style=\”position:absolute;top:0px;right:5px;color:#666;\”><small>Character limit = 150. Current characters: </small><input type=\”text\” value=\”0\” maxlength=\”3\” size=\”3\” id=\”excerpt_counter\” readonly=\”\” style=\”background:#fff;\”>&nbsp;</div>”); jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length); jQuery(“#excerpt”).keyup( function() { jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length); }); });</script>’; } return; } add_action( ‘admin_head-post.php’, ‘excerpt_count_js’); add_action( … Read more

if has theme mod

try this code: if( get_theme_mod(‘your_setting_name’) ){ //your code }else{ //your code } Note: get_theme_mod() return false if no value exist for your setting

Hide some items from Screen options in dashboard for products

The best option would be to use CSS to hide these columns and fields. Add this in your admin.css file to hide the SKU column table.wp-list-table .column-sku { width: 10% } To hide options in Screen Options add the following CSS in admin.css .metabox-prefs label:nth-child(2), .metabox-prefs label:nth-child(11), .metabox-prefs label:nth-child(12) { display: none; } FYI to … Read more

Returning Variables back into a template

There’s filters for that. Example: add_filter( ‘template_filter’, ‘wpse_102706_filter_callback’, 10, 2 ); function wpse_102706_filter_callback( $defaults, $case ) { $args = wp_parse_args( array( ‘some_key’ => ‘some_modified_value’ ), $defaults ); return $args } Then in your template just add in the defaults: apply_filters( ‘template_filter’, array( ‘some_key’ => ‘default_val’ ), ‘single’ ); More info in Codex about the Plugins … Read more

How to remove action from plugin?

You want: remove_action(‘um_post_registration_approved_hook’, ‘um_post_registration_approved_hook’, 10, 2); … to run after the original add_action, but before the action triggers the function um_post_registration_approved_hook The easiest way to do this, but I haven’t tested it, might be to just give your removal an earlier priority on the same hook: add_action( ‘um_post_registration_approved_hook’, ‘remove_my_action’, 9 ); function remove_my_action(){ remove_action(‘um_post_registration_approved_hook’, ‘um_post_registration_approved_hook’, … Read more

add_rewrite_rule with bottom priority doesn’t handle the WordPress pages

When you point a rule to anything other than index.php, it gets interpreted as external and written to the .htaccess file. After external rules are parsed, requests get directed to WordPress, which parses the internal rules in php. This is the internal version: function custom_rewrite() { add_rewrite_rule( ‘^(bar|baz|foo-.*)’, ‘index.php?my_var=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite’ … Read more