Hot answers tagged

13

This is a little tricky because sanitize_user allows spaces in usernames, meaning it difficult to avoid grabbing the whole phrase '@johndoe said that ... ' as opposed to just the actual username '@johndoe' and you have no separator at the end that would help. To avoid that I imposed a requirement that spaces in the username be replaced with '+'. function ...


4

Look at the P2 theme. It does this, calling them "Mentions". http://themes.svn.wordpress.org/p2/1.4.2/inc/mentions.php


3

I reworked (added another version of) my function to remove the if statement to check post status, as the post is scheduled to publish it turns out i don't need to check it again. /* the function */ function tcr_tweet2($postID) { /* get the post that's being published */ $post = get_post($postID); $post_title = $post-&...


3

ok, got it. Need to embed <script src="//platform.twitter.com/widgets.js" charset="utf-8"></script> manually And then fire twttr.widgets.load(); after appending the posts. Thx anyways, Rarst


2

This is because of a variable mismatch. Your function accepts $post_ID, but you don't actually use it. You're instead trying to reference a global $post object and doing your post format check with $post->ID. With the XML-RPC request, this won't work. Rewrite your function to use get_post() to fetch a post object from the passed-in ID: function ...


2

This might help you out if you haven't found an answer yet. /* BEGIN Custom User Contact Info */ function extra_contact_info($contactmethods) { unset($contactmethods['aim']); unset($contactmethods['yim']); unset($contactmethods['jabber']); $contactmethods['facebook'] = 'Facebook'; $contactmethods['twitter'] = 'Twitter'; $...


2

In the insert_posts function, before the line $post_id = wp_insert_post( $post ); add the following (and suit to your needs): Link to Twitter User Page $post['post_content'] .= '<a href="http://twitter.com/__USERNAME__">' .'Follow me on Twitter' .'</a>'; and/or Link to Twitter Status $post['post_content'] .= '<a href="'.$post['...


2

The mark-up surrounding the widget is malformed. IE isn't handling this as well as other browsers. <h1>Twitter</h1><h2><a href="http://twitter.com">Follow</h2> <div><h2><span class='twitterwidget twitterwidget-title'> Note the opening anchor tag before "Follow". This is never closed.


2

There is an extra action hook for scheduled posts: publish_future_post - it isn't very good documented though. There are occurrences of the hook in: /wp-includes/default-filters.php /wp-admin/includes/upgrade.php /wp-includes/post.php The hook invokes check_and_publish_future_post(). Read the linked information, if you want to inform yourself further. ...


2

Here's one way using the oembed_fetch_url filter to add the hide_media query parameter, that's also mentioned in the Twitter doc page you linked to: Set an oEmbed query parameter of hide_media=true or add a data-cards="hidden" attribute to the resulting <blockquote> element to prevent expanded content display. Here's an example: /** * Hide ...


2

I've used add_action ('transition_post_status', 'my_action'); and it works great for both posts that are published directly or in the future. The function my_action being: function my_action ($new_status, $old_status, $post) { if (($old_status != 'publish') && ($new_status == 'publish')) { // doing things. } }


2

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') ) ); }...


1

That tutorial is no longer valid as Twitter's API have changed June 2013. There are are some great tutorials that came out just after June 2013 for Twitter API v1.1. Why not use a plugin. It is actually better to go that root as these plugin developers keep their plugins up to date and are quick to modify them if someone like twitter change their API


1

I decided to use the built in Facebook sharer and Twitter sharer links, as provided on each site. It won't give complete functionality, but it it's perfect for a simple custom icon. Note: This will only work properly within 'the loop' HTML code to be inserted in your page template: <div class="social_icons"> <a href="javascript:window.print()"...


1

I have seen many plugins do it this way. But it definitely seems like a very tedious step to follow for the user in order to use the plugin... Is it the right method? Yes. Should I somehow, store my Consumer API key & secret details on my server? And any of my distributed plugins should automatically fetch it from my server? Further, are the Consumer ...


1

Twitter has some limitations upon file extensions. I see that you're passing on some variables within your meta tag. https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup.html URL of image to use in the card. Images must be less than 5MB in size. JPG, PNG, WEBP and GIF formats are supported. Only the first frame of an animated ...


1

As you can see from the source of get_the_excerpt there is a filter toward the end to modify the result. This is probably the most future proof approach. If at some point the blog will have manually written excerpts, these will be used. That would not be the case if you write a custom function for the twitter card. So, let's start here: add_filter ('...


1

In your theme, you'll need to most likely modify the "header.php" template. It should include the tag of html output for every page of the site. Within the tag, you can use a conditional call to check the result of both the queried object type and id using: get_queried_object(). For instance, you would have some php like this in the tag of header.php: ...


1

Yes, what you want to implement is cards. This is basically the concept of injecting metadata into your site that tells Twitter how you want it to be presented. If you wanted to do it using code, you could implement it doing something like this (barebones version): add_action( 'wp_head', 'wpse_add_twitter_metadata' ); function wpse_add_twitter_metadata() { ...


1

I think this is not good idea - create many enter points. Open Web Inspector and check your URL which using in JS code. But much better use the default admin_url( 'admin-ajax.php' ) to creates path which should be used in Java Script.


1

You are missing a few parts here to make this work You need set the global $post in your function You cannot use template tags directly without setting up postdata You need to add the post ID to get_permalink() You have a lot of syntax errors. Compare my code with yours You can try the following: (CAVEAT: Untested) function add_twitter_cards() { global $...


1

You have a couple of conflicting arguments here, but what you want to do is completely possible. To keep something out of the RSS feeds, and considering it really is a different type of content from your blog posts, I'd recommend a custom post type called "Links" or something. The custom post type will have its own archive and RSS feed, separate from your ...


1

get_the_tags() with a little bit of processing will do it: $tags = get_the_tags(); $tag_list = wp_list_pluck($tags,'name'); $tag_list = implode(',',$tag_list); var_dump($tag_list); Reference: http://codex.wordpress.org/Function_Reference/wp_list_pluck


1

Check out the embed API, particularly the functions wp_oembed_add_provider() and wp_embed_register_handler(). What version of WP are you running at the moment? And what happens when you place a Twitter URL on its own line in plain text? 3.4+ should handle embeds, never tried it myself.


1

New Twitter API requires authentication, you need to go to dev twitter and to create tokens. See documentation You need to use a library. I use this one EDIT: You need to create an application on dev twitter (it's just a basic information, fulfill the form) and then you'll get access to your tokens. The library will manage connection to the API if you ...


1

It is very likely because you are using the old Twitter API, for example: <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/USERNAME.json?callback=twitterCallback2&amp;count=4"> You will need to update your code to the new API: http://api.twitter.com/1/statuses/user_timeline.json?screen_name=USERNAME&include_rts=...


1

You are sending text unencoded. urlencode that just like you do the permalink. <a class="popup" href="http://twitter.com/share?url=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;text=<?php echo urlencode(the_content_limit(100, ""));?>"><img src="http://zitatezumnachdenken.com/wp-content/uploads/2013/04/twittersmall.png" ...


1

How to do remote requests in WordPress: Use the appropriate API First, there's the WP HTTP API, which should be used for such tasks. And second, one should never ever use the @ operator, as this one suppresses error messages or notices and will successfully lock you out from troubleshooting your bugs. Just because you can't see it, doesn't mean that it's ...


1

There is a jQuery event hooked to that link. Here is the function that is called whenever you click one of the sharing links: function (){ window.open( jQuery(this).attr( 'href' ), 'wpcomtwitter', 'menubar=1,resizable=1,width=600,height=350' ); return false; } This is added by the JetPack plugin and will attempt to open a dialog window with the ...


1

$post isn't available during {$new_status}_{$post->post_type}, but $post_ID is. We pass that to the function and then call in $post globally. I should have also been testing using get_post_format(), not for a type. After those corrections, everything seems to be running smoothly with the caveat that if the post is not auto-saved or saved as a draft ...


Only top voted, non community-wiki answers of a minimum length are eligible