Wordpress shortcode in RSS feed - wordpress

I'm trying to render shortcodes in my WordPress 4.3 RSS feed, by adding a filter to my theme's functions.php like this:
add_filter('the_content_feed', 'do_shortcode');
add_filter('the_excerpt_rss', 'do_shortcode');
The thing is it doesn't render like it does in the web version, for example for the appbox it shows this:
instead of this, which i see in the article:
How can I make it show the same?

Related

Is there some way to insert custom archive loop to any theme from plugin?

I'm coding plugin that create custom post type with custom fields. Now I need to build custom archive/category/tag templates which should contain custom fields.
The problem is that I couldn't insert template part inside archive loop from plugin.
Is there some hook to insert custom loop inside activated theme? Something like this:
add_filter('the_content', 'change_content_in_single_post');
Now I'm using this hook:
add_filter( 'template_include', 'change_whole_cpt_archive_template' );
... but when I use template_include hook it changes whole template and I need to do something like the_content filter. That hook get template of current theme and replace standart content template with my custom template - make it part of activated theme. It makes my CPT single page template compatible with any wp theme. Now I need to replace standart archive loop with my custom loop. For example: on archive page show posts without images... It must be something that replace result of standard get_template_part() function with custom template from plugin. That's what I`m searching for...
Anyway, maybe you know some better ways to make plugin (archive template) compatible with wp themes?
Huge thanks for any help!
you need to introduce some logic to only run on your cpt archive page.
add_filter( 'template_include', 'change_all_archive_template' );
function change_all_archive_template($template){
if ( is_post_type_archive('cptname') ) {
$template= 'find the template!';
//if( file_exists ) --> look in theme 1st??
//else --> load from plugin..
}
return $template;
}
There are quite a few plugins that use this technique to look in the active theme 1st and if not found, find the file in your plugin.
I found solution in woocommerce plugin files.
So... the best way to build custom archive template from plugin is to use template_include hook and in custom template file set header and footer from activated theme:
<?php get_header();
// custom archive loop
get_footer(); ?>
To make it more compatible with any wp themes use stanard wordpress and bootstrap classes.

Hide Shortcodes From Wordpress RSS Feed

I added Adsense to my content via shortcodes. But Adsense codes appears in RSS too. How can I hide shortcodes from RSS Feed and show only for in posts ?
I am using sahifa wordpress theme.
You will need to alter how the RSS is output.
All the RSS styling files are located in the wp-includes folder and are titled as follows:
feed-rss2.php
feed-rss.php
feed-rdf.php
feed-atom.php
feed-atom-comments.php
feed-rss2-comments.php
Then within these files, you need to find where it calls the function the_excerpt_rss(). This calls out the content in excerpt format.
You will need to enclose this in a function called strip_shortcodes().
As an example from feed-atom.php line 70:
<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php strip_shortcodes(the_excerpt_rss()); ?>]]></summary>
Hope this helps

Wordpress shortcodes working in php but not in text editor

I seem to be having a problem outputting shortcodes from the wordpress text editor. The shortcodes work fine when echoing from php but it is only in the text editor they simply produce what is written.
I have added the following lines to my functions.php:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
But this has no effect. This is happening across multiple plugins. Does anyone know why this might be happening?
Thanks!
So I've solved this. I figured out that this was only happening on custom templates. I then queried that issue and found that you have to use the_content() function to extract the content within your custom template and have shortcodes work. This is because the_content() parses the content in a manner that will make your shortcodes work.

shortcode in model page in twentytwelve theme?

I create a page in the model twentytwelve theme and I install the plugin cool video galery. my problem if I create it shows me the shortcode, not the video, how do I correct the problem?
Have you try to use do_shortcode function for using shortcode in Template.
So, Suppose if you short code is [cvg-gallery galleryId='gallery-id'] then wrap it with do_shotcode. Like
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode('[cvg-gallery galleryId='gallery-id']');
And then use it in template or in Lightbox.

How do I create a custom WordPress page?

I want my WordPress blog to have a page called music. On that page I will query the DB for posts with the category music and then change around the look and feel of the posts. So I can't just put a link to /categories/music/ because I want to do custom work on the posts.
Should I put this code in a separate php file and link to it? I think I may lose access to all the nice WordPress API calls if I do that.
I was thinking about using a filter, but I am not sure which one to use. I was thinking something like the following except the_title has not been grabbed yet so I cannot check the title.
function show_music(){
if( is_page() && the_title('','',false) == 'music' ){
echo "got here";
}
}
add_filter('pre_get_posts', 'show_portfolio');
How would you go about this?
You need to put the below code in the file, and then put the file in the Theme folder. Then you can create a page using Wordpress pages and select a page template with the name you put in this comment:
/*
Template Name: Something Goes Here
*/
You need to create custom page within your theme. If you dont have idea how to create custme page or template page in WordPress theme then view my easy tutorial How to create template page in WordPress

Resources