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

Shortcode created to check language not works

In a shortcode you always need to return something. It’s also good practice to make your code very logical and readable. Here are a list of PHP Logical Operators: http://php.net/manual/en/language.operators.logical.php Complete List of WordPress Locale Codes: https://wpastra.com/docs/complete-list-wordpress-locale-codes/ Below an example as English as a backup/fallback language: function coupon_shortcode() { $logged_in = is_user_logged_in(); if (get_locale() == … Read more

Code to auto expire posts after 30 days

There are some issues with your query $daystogo = “30”; $sql = “UPDATE {$wpdb->posts} SET post_status=”draft” WHERE (post_type=”post” AND post_status=”publish”) AND DATEDIFF(NOW(), post_date) > %d”; $wpdb->query( $wpdb->prepare( $sql, $daystogo ) ); You do not want to untrash trashed posts by declaring them as draft, right? And you really do not want to make every automated … 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

Enqueue Javascript Correctly for 3.5

Never de-register core-bundled scripts in the WP-Admin. You shouldn’t do it on the front end, either, unless you really, really know what you’re doing. But especially in the WP-Admin, just use the core-bundled scripts. Also, when you use core-bundled jQuery UI, WordPress already knows that jQuery is a dependency. Just change the first callback 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