Wordpress Publish Date Shortcode - wordpress

This sounds like it should be something simple or there should be a simple shortcode plug in to achieve this but i have searched and searched for almost and hour now and can't find the answer. All i am trying to do is display the post's published date in the body text. Example: [meta = "Date"]. Is there an easy light weight solution to achieve this. I simply need to publish the post date inside the content. Thanks.

There is a good article on how to do this with a custom plugin or snippet of code for your theme
https://krogsgard.com/2012/create-a-shortcode-to-show-when-a-post-was-last-updated/
You can create a shortcode easily within WordPress. This is a sample of code that you can either place in a new plugin file. For creating a plugin file, visit https://codex.wordpress.org/Writing_a_Plugin , basically, you create a file, lets say my_shortcodes.php and place it in the /wp-content/plugins/ folder. In that file, you would have the following.
<?php
/*
Plugin Name: My Plugin Stuff
Plugin URI: http://domain.com/
Description: My Plugin Stuff
Version: 0.1.0
Author: Your Name
Author URI: http://your-website.com/
License: GPLv2 or later
*/
function shortcode_post_published_date(){
return get_the_date();
}
add_shortcode( 'post_published', 'shortcode_post_published_date' );
Then you would use the shortcode in your post [post_published]
Disclaimer:
This is a sample of what it may look like. You may have to make some modifications to it to make it work the way you want. You may not be able to copy and paste this into your code and it work right away.

Related

how to customize post meta in wordpress?

currently my theme on WordPress is Neve , and my posts all over the blog shows the following meta info :
https://i.stack.imgur.com/ynu71.jpg
where :
1- post title
2- post author
3- post date
4- post category
i want to replace these post meta with similar to this:
https://i.stack.imgur.com/Xywa9.jpg
for this purpose i have created a child theme and then installed snippet plugin to add php code easily and deactivate it once it is not working . unfortunately i could not find the code that can do the required modifications on that post meta :
https://i.stack.imgur.com/uwCrS.jpg
can any one provide a full php code to modify all these changes in one time after pasting into snippet ? or if there is another way i can do it ?
You'll have to create a child theme (already done) where you can override the current blog post template, instead of using a snippet plugin. To do this, copy the blog post template file from your theme and add it to your child theme.
WordPress will now read your child theme template instead of your theme's template, and you can easily modify the DOM from there, and shape the layout/text however way you want. (You can use the theme editor built-in in WordPress to modify the new child theme file. No plugin required.)
This is the proper way to modify a post page without plugins, and you can easily grab thing such as a post date, author, etc. via WordPress' built-in function. Example of how to get the author name of a WordPress post in PHP.
As for, 'latest edition' date, I will lend you a snippet I wrote for a client as WordPress. This will return the date at which a post has been modified as long as it is different from the publishing date (tweaks are common right after publication so it's a tad pointless to show a "last edited date" as the same as the publication date).
function current_post_last_edited_date_formatted() {
if(get_the_modified_date() !== get_the_date()) {
return '<p class="last-edited"> Last edited <span class="data">'.current_post_last_edited_date().'</span></p>';
} else {
return '';
};
}
The function you see called in the condition are WordPress core functions. =)

Extend existing wordpress plugin

I was wondering if I could extend a existing wordpress plugin. For example adding some new features but without touching the original plugin files. Is this possible?
EDIT
I found the solution. For example in woocommerce plugin, I need to add some html to the sigle product so I wrote in function.php:
add_action( 'woocommerce_single_product_summary', 'woocommerce_single_product_my_custom_function', 15 );
function woocommerce_single_product_my_custom_function(){
echo '<p>this is my html code</p>';
}
unless the original defines hooks to extend, I am afraid this will not be possible. I suggest the way you would do that is copy the plugin directory and give it a different name in its definition

Embedding Wordfaire into Self Hosted Wordpress

I am trying to get Wordfaire live blogging embed code to work on my site and having some problems. I created a new page for my live blog feed on site site and added the embed code to the html page in wordpress. When I test it out and try a test live blog nothing runs on the page.
Is there a trick to getting it to work on wordpress??
Thanks in advance to anyone that can assist!
It sounds to me that you are using the HTML view of the WordPress editor to paste the embed code, correct?
A better way would be to make a simple plugin that will create a shortcode with the embed code, then you use that shortcode to display the embed code on your page.
Example:
embed-shortcode-plugin.php
<?php
/*
Plugin Name: Plugin Name
Plugin URI: http://pluginurl.com
Description: Plugin description
Version: 1.0
Author: Author Name
Author URI: http://authorurl.com
*/
function embed_shortcode($atts,$content=null){
extract(shortcode_atts(array('optionname'=>'defaultvalue'),$atts));
// The extract() function above will allow you to do [shortcode optionname="defaultvalue"] in your pages and use $optionname to get the value below
// The extract() line is optional and can be removed
// $optionname = defaultvalue
return 'put your embed code here';
}
add_shortcode('shortcode','embed_shortcode');
// This will add the shortcode 'shortcode': [shortcode], change to whatever
?>
Put that in your plugins folder and then activate it. Alternatively, you could remove the stuff between the /* and */ and put that code right in your theme's functions.php file and it will run the same.

Where do I save widget code for wordpress?

I've googled around quite a lot, but can't seem to find where I should be saving the code for the widget I've created. It's a bit baffling.
So, can anyone tell me where I should save my widget?
Thanks,
John.
You need to put your widget code in either the functions.php file of your current theme, or within a plugin. In order to put it in a plugin, create a new folder in the plugins folder and create a .php file with the name of the folder you created within that folder. In that file, use this code to start your plugin:
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>
Obviously, change the values to something useful for your plugin. You can then paste your widget code into this file and it should be ready to use.
Sources:
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Plugin_API
As far as I know, widget (ie plugins) go in your wp-content/plugins folder eg. wp-content/plugins/YOUR WIDGET/
Is that what you need?
You can save your code in the file of wp-content\themes\YOUR-THEME-NAME\functions.php.

How to make custom post template in Thesis theme

I'm struggling to use custom post template in thesis. I would like to use different layouts for different posts. There are many tutorials for using custom page template but I can't find ones for posts. I'm new to Thesis so I probably miss something but if someone knows how to or tutorial that mentions about it, please share with me. Thanks in advance!
One way to do this (that goes against the thesis custom_functions.php file, unfortunately) is to use this plugin:
http://wordpress.org/extend/plugins/custom-post-template/
Then, create a page called, say, news.php and put this code inside
<?php
/*
Template Name Posts: News
*/
/*
Your custom code goes here
*/
Then, once you upload this to your thesis folder, it should show up in the post-template dropdown.
?>
Answer #1 in this post might provide you with a way to style posts in Thesis or elsewhere, as long as you're using WP 2.8+:
http://www.smashingmagazine.com/2009/10/20/10-useful-wordpress-hacks-for-advanced-themes/

Resources