How would I use this filter to change the output of the date format to “Twitter time”?

WordPress has a core function human_time_diff that does what you want, using it with the filter you provide you have someting like so: add_filter(‘latest_tweets_render_date’, function( $created_at ){ $date = DateTime::createFromFormat(‘D M d H:i:s O Y’, $created_at ); return sprintf( ‘%s ‘ . __( ‘ago’ ), human_time_diff( $date->format(‘U’) ) ); });

PHP in CSS file?

You can use wp_add_inline_style(). Let’s assume you enqueue your css like so add_action( ‘wp_enqueue_scripts’, ‘add_my_style’ ); function add_my_style() { wp_enqueue_script( ‘my_style’, get_template_directory_uri() . ‘/mystyle.css’ ); } Then you can change the function like so: function add_my_style() { wp_enqueue_script( ‘my_style’, get_template_directory_uri() . ‘/mystyle.css’ ); $style = “#mainnav li:after { content: url(‘{theme_url}/images/nav-divider.png’); }”; $style .= “#another-example { … Read more

Troll the hackers by redirecting them

I understand this isn’t exactly what you’re looking for but these hackers are most likely bots and redirecting them won’t matter at all. I suppose you could modify the below code if you reallllly wanted to but this will redirect anybody looking for an author back to your homepage. RewriteCond %{REQUEST_URI} ^/$ RewriteCond %{QUERY_STRING} ^/?author=([0-9]*) … Read more

Parse error: syntax error, unexpected end of file

I just want to add to the two answers given on this matter. It is important to know that if you use if($the_query->have_posts() ) : you will need to close that with endif; otherwise you will also get the same parse error as described.

Update post title from external file?

Sometimes I use this code when I want to run WordPress externally. update.php function find_wordpress_base_path() { $dir = dirname(__FILE__); do { //it is possible to check for other files here if( file_exists($dir.”/wp-config.php”) ) { return $dir; } } while( $dir = realpath(“$dir/..”) ); return null; } define( ‘BASE_PATH’, find_wordpress_base_path().”https://wordpress.stackexchange.com/” ); define(‘WP_USE_THEMES’, false); global $wp, $wp_query, … Read more

Update postmeta after theme switch

I am going to guess that you have your code in the theme, probably functions.php. That code will only load when the theme is active, and after_switch_theme only runs after the theme change. There is no before_switch_theme that I am aware of. You will need to have this code in a plugin or a mu-plugin … Read more

Exclude specific post from displaying

Post__not_in doesn’t need the minus or the ‘ ‘ Make it an array like this: ‘post__not_in’ => array(4135), Try adding the post ID into a variable e.g. $excludes = array(‘4135’); ‘post__not_in’ => $excludes

Function won’t run onclick using Ajax

1) Is your function working? First do a console.log( “it’s working” ); inside your function and check it on your browser’s console. If it’s not showing when you click, you must refactor your function. 2) Have you defined ajaxurl? Unlike on the admin side, the ajaxurl javascript global does not get automatically defined for you, … Read more

How to sent a email outside WordPress?

If you are outside WordPress and want to load Wordpess, you only need: require (‘/path/to/wp-load.php’); In some situations you may want to load only some WordPress functions, for example: define(‘SHORTINIT’, true); require (‘/path/to/wp-load.php’); require( ABSPATH . WPINC . ‘/formatting.php’ ); require( ABSPATH . WPINC . ‘/meta.php’ ); require( ABSPATH . WPINC . ‘/post.php’ ); //Load … Read more