Redirect logged in users if they are on a specific page

One problem is that you’re hooking in too early. Reference the Hooks API Action Reference. Template conditionals such as is_page() are only available after the query has been set up and parsed. The earliest action that you can usually safely rely on query conditionals is pre_get_posts. You’re hooking into init, which fires much earlier: muplugins_loaded … Read more

Fire jQuery function when post edit screen loads

You have your jQuery hooked too early. The jQuery library has not yet loaded when the load-(page) action is fired. Use admin_print_scripts to print inline scripts. That action comes after scripts are enqueued. Here’s your original code using admin_print_scripts: add_action( ‘admin_print_scripts’, function () { $status = “status-started”; if($status == ‘status-started’): ?> <script> jQuery(document).ready(function($) { /* … Read more

How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?

There are 3 methods. Somewhat weird but since this text is internationalized you can filter the output. This is just an example to remove the text, the link is still present in the source. add_filter(‘gettext’, ‘remove_powered_by’, 20, 3); function remove_powered_by( $translated_text, $untranslated_text, $domain ) { $custom_field_text=”Proudly powered by %s”; if ( !is_admin() && $untranslated_text === … Read more

Using action hooks inside of a shortcode

Try this: function example_shortcode( $atts ) { $shortcode_output = “<p>Some shortcode content.</p>”; $shortcode_output .= “<p>More shortcode content.</p>”; ob_start(); do_action(‘below_shortcode’); $below_shortcode = ob_get_contents(); ob_end_clean(); $shortcode_output .= $below_shortcode return $shortcode_output; }

How to make post and comment count unclickable with dashboard_glance_items hook

The dashboard_glance_items filter is only useful for modifying the extra elements. The posts/comments data elements have already been displayed. Here are three ideas: Method #1 – Use the dashboard_glance_items filter: You can use the following filter setup, to remove the posts/pages/comments elements from the output of wp_dashboard_right_now(). The trick is simple, foul WordPress to think … Read more

Difference between hooks Plugin_loaded and admin_int?

plugins_loaded fires once activated plugins have loaded. This fires on both admin and public screens. admin_init fires as an admin screen or script is being initialized. This fires only on admin screens. The typical order for firing of hooks on the admin screen is: muplugins_loaded – this is the first hook available to must-use plugins … Read more

RSS feed with specific keyword

You can modify the list of posts displayed in feed using pre_get_posts action. And to target only feeds, you can use is_feed conditional tag. So such code can look like this: add_action( ‘pre_get_posts’, function ( $query ) { if ( ! is_admin() && is_feed() && $query->is_main_query() ) { if ( isset($_GET[‘q’]) && trim($_GET[‘q’]) ) { … Read more

add_action customize_register not working

You always need to be sure that three things are defined (section, setting and control). If you are adding a control to an already defined section, i.e. title_tagline, then you don’t need to re-register it, but always define the setting and the control. //adding setting for copyright text add_action(‘customize_register’, ‘theme_copyright_customizer’); function theme_copyright_customizer($wp_customize) { //adding section … Read more