Skip to main content
13 events
when toggle format what by license comment
Nov 11, 2016 at 2:09 vote accept d.ariel
Nov 10, 2016 at 15:36 comment added Ranuka I think now WordPress part is over. You need to apply few PHP functions to make it as you want. Read this : stackoverflow.com/questions/4880930/… And to get first 70 chars you can use substr function. Read : stackoverflow.com/questions/3787540/…. It is better to ask normal programming questions like you have asked in last comment, from stackoverflow.com.
Nov 10, 2016 at 15:27 comment added d.ariel @Ranuka If you think this is out of the scope of the initial question i'll gladly marked as answered and try my luck with another question if that's what you suggest. Thank you so much for everything this far!
Nov 10, 2016 at 15:26 comment added d.ariel Thank you it works great. I'll mark this question answered. I've got one more question though regarding this subject if you don't mind @Ranuka . My meta description now looks like this: <meta name='description' content='Harry potter book 1 chapter 12 &#8211; Chapter Title Here--Words from the post content which is way too long for the meta description which i'd like to truncate to maximum of 70 characters;'/> I'd like to get rid of the &#8211 which I think is what it is converting into special characters, remove the double hyphen when it goes from title to excerpt and allow max 70 char.
Nov 10, 2016 at 10:55 comment added Ranuka .Try to use add_action('wp_head','add_meta_des',1); instead of add_action('wp_head','add_meta_des');. If it is not suitable you have to use different different numbers to check it.
Nov 10, 2016 at 10:30 comment added d.ariel @Ranuka Your updated code is exactly right. Could you help with positioning the meta data higher up on the page preferably closer to the <head> tag.
Nov 10, 2016 at 10:20 comment added Ranuka @d.ariel Ya, there was a problem. I updated the code. I tested it and it worked fine in my site. Now please try the updated code and let me know the result.
Nov 10, 2016 at 10:18 history edited Ranuka CC BY-SA 3.0
added 218 characters in body
Nov 10, 2016 at 9:29 comment added d.ariel @Ranuka I read over the add action page you sent me but was unable to identify from that page how I can change where on the page the meta description is inserted. Possibly priority? But will that dictate the priority for the entire page or all the functions? If I set priority to 1 would that mean it loads at the top before css etc near the top of the header? Also I read the other links regarding the excerpt, using your code should have worked and pulled the "automatic" excerpt from the page but for some reason it didn't and it only used the title? Additional info very appreciated
Nov 10, 2016 at 8:46 comment added Ranuka More info about WordPress excerpt : codex.wordpress.org/Excerpt and if you want to get it from content read wordpress.stackexchange.com/questions/141466/… . And add_action has two another optional Parameters. Check it here: developer.wordpress.org/reference/functions/add_action You can use those parameters display in right place.
Nov 10, 2016 at 8:26 comment added d.ariel Ranuka I put this at the bottom of my functions.php file and it did display but there were a couple of things wrong. #1 It showed up for some reason at the bottom of the page instead of at the top where my other meta data is located and #2 It did not get an excerpt. I'm not 100% sure how the .get_the_exceprt() is supposed to work or if that was just a sample but the get the title did work as expected. When using .get_the_excerpt() does that automatically get the first few words of the main body content?
Nov 10, 2016 at 5:10 comment added Mayeenul Islam I think, instead of using is_single(), using is_singular() is more broad in this particular situation.
Nov 10, 2016 at 4:32 history answered Ranuka CC BY-SA 3.0