Wordpress adding custom fields into post's front end - wordpress

i want to make a wordpress plugin that will display some content at the end of each post. let's say for example 'Hello world'.
But looking at the wordpress API, i don't find any relevant indications about how to do this.
i don't want a widget, but only a plugin that does only that: displays me a static text at the end of every article.
any idea about how this should be done?
thanks!

See if this forum post helps you:
http://wordpress.org/support/topic/simple-wordpress-plugin-to-add-actionable-text-after-blog-content-feedback?replies=1
The lines doing the magic are:
...
add_filter('the_content','now_what_pjrvs');
...
function now_what_pjrvs($content = '') {
return $content . $text;
}
Where $text is the code that you want to add at the end of the post content.
Hope it helps.
Tell me if you need more references.

Related

How to Add "itemReviewed" in WP-postratings plugin

I want to set up the markup of Reviews on the site that would be in the snippet search engine displayed stars and the author of the review.
CMS site: WordPress 5.3 - Astra theme
I use the plugin: WP-Postrating (https://wordpress.org/plugins/wp-postratings/)
1.changed the type of markup in function.php using the filter as described in the plugin instructions:
add_filter( 'wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype' );
function wp_postratings_schema_itemtype( $itemtype ) {
return 'itemscope itemtype';
}
Markup is now defined as Review link
But because of the error: It is necessary to specify the value for the itemReviewed field.
Stars and the author are not displayed in the snippet of the search system.
Please give us a hint. What code should I add to function.php to add this field? And what would you like to see in this field, for example, the title of an article or manually fill in itemReviewed. Perhaps you need to add some special field to the article editor.
I would be very grateful. The employer wants to do this, I am a novice developer at https://improvecraft.com/
It's an old question and you probably figured out how to add this code. If someone still needs it, this code should work (and you can change also itemtype):
add_filter( 'wp_postratings_schema_itemtype','wp_postratings_schema_itemtype');
function wp_postratings_schema_itemtype($itemtype) {
global $post;
$title = get_the_title($post->ID);
return 'itemscope itemReviewed="' . $title . '" itemtype="http://schema.org/LocalBusiness"';
}

Wordpress: How to pass additional Content to the blog-preview page?

For each blog-post on my wordpress-blog I'd like to have Teaxtarea where i can pass additional content for that post.
In my case that would be an unordered list which contains a quick overview of the content.
That additional content should be displayed in the preview of the post on the blog-preview-page.
My problem:
I am actually not sure on how to best add this additional content and then pass it to the preview.
Do I use wordpress' custom fields for something like this?
I'm gratefull for a push in the right direction.
Thank you,
Nils
If I understand you right, I'd take a look at "custom meta boxes" functionality - it allows you to add any type of additional input into your blog post admin area, and than display its content on front-end however you like.
There's a nice tutorial series on that topic, with example code snippets:
http://wp.tutsplus.com/series/reusable-custom-meta-boxes/
And if you'd like to display the textarea content only in preview mode, you can use appropriate conditional tag in you template file:
http://codex.wordpress.org/Conditional_Tags#A_Preview
The conditional tag is_preview returns true when a single post is viewed in Draft mode. The following will append post meta to the content when a post is being previewed:
function so16799607_preview( $content )
{
if ( ! is_preview() )
return $content;
return $content . get_post_meta( get_the_ID(), 'my_post_meta', true );
}
add_filter( 'the_content', 'so16799607_preview', 10, 1 );
You should check out Advanced Custom Fields. That's a really stable plugin that lets you create custom meta boxes in posts, pages and custom post types. That plugin does exactly what your question states. Need al little PHP to get stuff from your database, but that is as easy as:
<?php the_field(field_name);?>
And the documentation is pretty good. And if you don't like a plugin, it exports the PHP as well.
Anther tool that does the same is Pods Framework. Both powerfull extensions to any WP install in my opinion.
Hope this helps.

WordPress plugins - don't print the comments on a post page

I'm making a plugin where I want the comments in a single post page not to be printed at all. I need to query the database myself and print my own html with the results.
How can I make WordPress to not print the comments, without disabling them?
Thank you
EDIT:
as a suggestion, I am using:
apply_filters('comments_template', array($this,'comments_template'), 10, 1);
function comments_template($template){
$template = '';
return $template;
}
nothing happens, what am I doing wrong?
You could use the comments_template filter to make WordPress use your plugin's template file rather than the current theme's.
EDIT: based on your edited code: unfortunately you need to have an actual file, the path to which you return in $this->comments_template()...
class MyPlugin{
//add the filter somewhere...
function comments_template($template){
return dirname(__FILE__) . "/my_comments_template.php";
}
}
The file plugin_dir/my_comments_template.php must exist, otherwise WP falls back on the default theme's comments.php. See wp-includes/comment-template.php on lines 911-917.
In plugin_dir/my_comments_template.php you could call `MyPlugin::do_comments() or something like that. I don't know any other way around this. Let me know if you find a better way.
Cheers, Chris

Possible to add a read more link in an RSS Feed?

This may be a weird or stupid question, but I have the following code (http://pastebin.com/PTFtqkvs) and I want to place a simple "read more" link after the description which links to the the article in the rSS feed - however whatever I do isn't working. Is it even possible to add this option and still conform to the rSS guidelines? This is built using a WP system to show Posts in a certain category.
Any help would be greatly appreciated.
You can hook onto feed specific hooks to add that to your feed content. Something like this in your theme's functions.php would work:
function my_super_awesome_feed_linker( $content ){
$extra = "<a href='" . get_permalink() . "'>Read More...</a>";
return $content . $extra;
}
add_filter( 'the_excerpt_rss', 'my_super_awesome_feed_linker' );
This will add a 'read more' link to all your feeds, though.
In order for this to work, you need to use a normal WordPress loop and the function the_excerpt_rss() instead of what you do in your code, echo $post->post_excerpt;. I've modified your pastebin here:
http://pastebin.com/6Y8pewhW
Also, just a word of advice, this won't really work as a template. WordPress has already sent headers by the time you've gotten to the page's template file. So you'll need to find a way to get those headers sent correctly, or to override them. The two easiest ways would be to filter the header content or to query the posts at 'wp_loaded' before headers are sent.

Displaying code snippets in WordPress

Ok, not technically a programming question but I want a plugin for my WordPress blog that displays code snippets.
Can anyone here recommend a good one? Also, do you guys know which one Jeff uses on codinghorror. That one looks really good.
Thanks.
wordpress.com claims to use Alex Gorbatchev’s syntaxhighlighter Google Code project.
I guess you might be interested in run-this - there is a wordpress plugin to allow your readers to run your snippets in the browser.
For WP-Snippets, I use Prettify.
You should probably use a plugin for escaping characters to be able to display code without having to do it yourself, or your code wont be displayed. Or just put this in functions.php in your theme folder to do this automatically:
function bbcode( $attr, $content = null ) {
$content = clean_pre($content); // Clean pre-tags
return '<pre"><code>' .
str_replace('<', '<', $content) . // Escape < chars
'</code></pre>';
}
add_shortcode('code', 'bbcode');
And then wrap your code with [code]<?php echo 'hello world!'; ?>[/code]
Source: Code in posts

Resources