I'm trying to remove the the_guid() function that appears in feed-rss2.php. I've tried remove_action('rss2_item', 'the_guid') or remove_filter but nothing happens. I’ve also tried different hooks like the_content_rss...
The function appears on line 43 of feed-rss2.php, enclosed by <item></item>.
Update
With echo current_filter(), I found that the hook is do_feed_rss2. But I still can't remove the function.
You can override the output of that function via a filter.
add_filter('get_the_guid','my_get_the_guid');
function my_get_the_guid($guid) {
$my_guid = 'foo';
return $my_guid;
}
Using that you can override the GUID output with anything you want. You can't delete the node in the RSS output, but you can control its content. If you want to delete the node all together you could create your own XML template, keep it on your theme, and then use the template_redirect action to force load your template instead of the default.
Hope that helps!
Feed Wrangler plugin works great for customizing feeds:
http://wordpress.org/extend/plugins/feed-wrangler/
Basically, install the plugin, denote a feed with a slug (ex: no-guid), then add a feed-no-guid.php file to your theme. You can use the default feed files in wp-includes/ as a base and delete or add whatever items you want. That way, you get complete control of the feed and a clear upgrade path in the future.
Looks like line 40 in /wp-includes/feed-rss2.php:
<guid isPermaLink="false"><?php the_guid(); ?></guid>
Try deleting that and see what happens; it's the only reference to the_guid in the file
Related
I'm working on a Wordpress theme, where I want to change the generated markup of the [product_category] WooCommerce shortcode. I browsed through the templates directory in the plugin, but can't find the file related to this particular shortcode.
So my question is, which files I have to copy to my template and modify to change the HTML outcome of [product_category]? (CSS modifications are already done, but I need to display a very different HTML markup, and I don't want to hack around with JS).
Also it would be better not to rewrite the whole function with a hook, but change the original HTML a bit (for example, set the background color based on a custom meta field).
Esiest way :)
add_shortcode('test','test_show_shortcode');
function test_show_shortcode( $atts ) {
echo do_shortcode('[products limit="100" columns="..." category="..."]');
}
[test]
This is my first time attempting to make a Wordpress plugin. I would like to insert three lines of code into the post-template.php file under wp-includes. I am thinking I will need a way to override the function, in this case, get_the_content, so that it calls my plugin's version of the function instead of the default one.
Based on what I've searched, it is not a good idea to override the core files so I'm hoping there is a simple way to modify the function through my plugin.
What would be the best method to go about doing so?
You could overwrite it using the same function name inside your plugin, also you could create a child theme and inside that you can copy the file post-template.php so it will load the edited version instead without updating issues, or it may be possible (if its plugable) to overwrite or edit it using a hook, check out this answer: https://stackoverflow.com/a/17202451/7862006
You got that right. Never modify the core files directly for these reasons. However, luckily there are different ways to achieve what you want in WordPress. The simplest would be to add a filter in functions.php (if you are using a theme find the functions.php inside ../themes/..) like this:
add_filter('the_content', 'new_content_filter');
function new_content_filter( $content )
{
$new_content = 'hello';
return $new_content;
}
This will get the content and apply a new filter on it.
I am having a problem with a site I am developing with wordpress.
It happened after upgrading to the latest version (4.7)
Anyway. Go to the site www.scientized.com (just dummy content for now), and go the source. At around line 124 you see the tag <style type="text/css" id="wp-custom-css"> and then after some css is loaded.
The thing is, is that this some of my old css code from way early. To make life easier and to isolate the problem I have delete all css in my child themes style.css as well as the custom css in the customizer, and delete jetpack just to be sure. Yet this css is being loaded from somewhere. I have file explored the crap out of my site trying to find where this is located, but couldn't find anything.
I have found that in the wp-includes/theme.php there is this function:
function wp_custom_css_cb() {
$styles = wp_get_custom_css();
if ( $styles || is_customize_preview() ) : ?>
<style type="text/css" id="wp-custom-css">
<?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div > span` is not interpreted properly. ?>
</style>
<?php endif;
}
so this wp_get_customer_css() function is calling the old css from somewhere -- I tried to follow the functions back to see where - but my php is not that good and got lost. Does anyone know where this is being loaded from?
I think I need to know where the JetPack custom css location is. I have read it is generated dynamically -- so I am not sure how to go about the problem.
Edit: I dont get the text box in the custom css area in customizer. Where is this text located?
Edit: I dont get the text box in the custom css area in customizer. Where is this text located?
The Additional CSS content is stored in wp_posts database table as a separate record. It's post_type is set to custom_css. To find which post is assigned to the field, you need to look in the option theme_mods_{your theme's slug}.
For example, here is the one from my test Sandbox site which is running the Genesis Sample theme. The post ID is 31, per the key custom_css_post_id.
How do I check my site?
You can go directly into your database via phpMyAdmin and look in the wp_options table. Or...you can do this:
add_action( 'init', 'check_custom_css_post_id_theme_mod' );
function check_custom_css_post_id_theme_mod() {
var_dump( get_theme_mods() );
}
The above code will display the theme mods for your current theme. Note the one that is keyed as 'custom_css_post_id'. That one holds the ID to the post for the CSS.
How to Remove It
To remove a theme mod, you use remove_theme_mod( 'custom_css_post_id' );. See codex for the documentation on this construct. It will remove the binding between the Additional CSS. How? It deletes the sub-option.
Note, it does not delete the post record, meaning you'll have an orphaned record in wp_posts.
The wp-custom-css is loaded from custom css & js
How can I place a default text (hashtag) in the Custom Message?
The textarea is (located in line 643) under jetpack/modules/publicize/ui.php
I tried to put the text in front of $title in various ways, like:
<?php echo "#myhashtag $title"; ?>
or
<?php echo '#myhashtag '.$title; ?>
but it just echoes the text, not the $title.
Any ideas will be greatly appreciated.
You can use the approach of this Wordpress plugin i made (Publicize With Hashtags), which does exactly that. It basically use and action trigger bound to the 'save_post' native event.
If you want to develop your own one you can have a look at my Source Code on the project's GitHub page or in this installation & usage guide I wrote about it.
You can add a filter, like so, to your theme's functions.php or a site-specific plugin:
add_filter( 'wpas_default_prefix', 'add_default_publicize_hashtag_prefix', 10, 4 );
function add_default_publicize_hashtag_prefix() {
$default_tags = '#yourhastaghere ';
return $default_tags;
}
This will add your default hashtag before your title without you needing to hack the WordPress core.
jetpack/modules/publicize/ui.php itself states in its comments:
/**
* Only user facing pieces of Publicize are found here.
*/
You added your hashtag in the textarea which allows admins to enter a custom message (click edit and it will slide down with your hashtag).
As #Yazmin mentioned, the best way to permanently edit the message is using a filter. The filters available are wpas_default_prefix, wpas_default_message, and wpas_default_suffix.
Personally, I had no success using these filters and I'm interested in a working solution to this issue myself.
i've written a plugin which shortcodes can easily be used in every post and page. As this plugin can be useful in a sidebar as well i want to make the text widget usable for my shortcodes.
When i googled this i found out that i can use the add_filter() function to ensure that, but this is only possible if i have access to the theme's functions.php. But as i am the creator of the plugin and not of the theme, this is not usable for me.
Does anybody know how i can make a shortcode which is introduced with a plugin usable in the widgets section?
Thanks!
Open your theme's function file.
Find a free spot after the opening php tag that isn't part of a function.
add this:
if (!is_admin())
{
add_filter('widget_text', 'do_shortcode', 11);
}
save the file and you should be all set.
Open your page in edit mode.
Select your page location and line where you want to add short code.
Add code here and update..