Fatal error: Call to undefined function add_action() – an untouched problem

get_stylesheet_directory_uri() returns an URL. The requested file is called like any other publicly available resource: without the context of the include statement. This is like opening the PHP file in a browser directly. There is no WordPress context, and the functions add_action() or add_filter() are not defined. Use get_template_directory() in parent themes and get_stylesheet_directory() in … Read more

Is there a way to push javascript or css ‘on-page’ in a template via functions.php

You can just hook into wp_head for CSS or JS, or wp_footer for JS (style tags need to be in the header): function wpse_276403_output_scripts() { ?> <script>alert(‘Hello world!’);</script> <style> body { background: #F00; } </style> <?php } add_action( ‘wp_head’, ‘wpse_276403_output_scripts’ ); function wpse_276403_output_scripts() { ?> <script>alert(‘Hello world!’);</script> <?php } add_action( ‘wp_footer’, ‘wpse_276403_output_scripts’ ); If your … Read more

Edit the_content function

Not exactly sure what you are trying to accomplish, but it looks like you are trying to prepend something to the beginning of the_content. Try this: add_filter(‘the_content’, ‘se24265_my_function’); function se24265_my_function( $content ) { $write=”hello world”; $new_content = $write . $content; return $new_content; } Most filters will provide a parameter or two for your function to … Read more

Stripping shortcode from custom excerpt function

Don’t use a custom function. You should use the hooks. You don’t have to strip shortcodes, wordpress does that for you automatically, just use something like this // setting higher priority so that wordpress default filter have already applied add_filter(‘the_excerpt’, ‘custom_excerpt_filter’, 11); function custom_excerpt_filter($excerpt) { // apply your logic of read more link here return … Read more

Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php

Every string goes through translate(), which uses the gettext filter. This mean you can try something like this: add_filter( ‘gettext’, ‘wpse6096_gettext’, 10, 2 ); function wpse6096_gettext( $translation, $original ) { if ( ‘Nickname’ == $original ) { return ‘Funny name’; } if ( ‘Biographical Info’ == $original ) { return ‘Resume’; } return $translation; } … Read more

Dynamically add sub-categories to any category in the menu

you can add them with the filter wp_get_nav_menu_items add_filter(“wp_get_nav_menu_items”, function ($items, $menu, $args) { // don’t add child categories in administration of menus if (is_admin()) { return $items; } foreach ($items as $index => $i) { if (“category” !== $i->object) { continue; } $term_children = get_term_children($i->object_id, “category”); // add child categories foreach ($term_children as $index2 … Read more

disable comments if array exists

Assuming you’re properly using comment_form() to output the comment reply form: if( ! array_key_exists( ‘comments’, $wp_query->query_vars ) ) { // Output the comment form comment_form(); } Edit Based on your comments.php code: // If the user isn’t logged in, don’t display comment form if ( is_user_logged_in() ) { global $wp_query; // If the post type … Read more