I create a custom payment for WordPress, is a simple code but I need to hide the code, I thought about creating a shortcode [custom_shorcode].
When I put the shortcode i need to display a custom html with php.
You can do this in the functions.php or a simple Plugin.
To create it in the functions.php of your child-theme, do it like this:
add_shortcode('your-shortcode', 'yourFunction');
function yourFunction(){
//do your stuff
}
You can find the documentation here
Related
I'm using shortcodes in my Wordpress page to display a responsive Google Map centered at specific location. To do it I'm using shortcode supported by external Wordpress plugin. Such shortcode is let's say [map address="New York"].
As all my Wordpress posts titles are names of the cities, I would like to automatize the process and be able to display the titles of the post in place of the address parameter in [map] shortcode.
Is it possible? Is there any way to do it? As far as I know nesting code or variables in shortcode isn't supported by Wordpress but maybe there is some kind of a workaround.
The same behavior I'd like to accomplish for 'custom field' - really similar situation.
I'd appreciate any help and any advice
Try to put this code to functions.php file in your theme:
function mymap_shortcode() {
echo do_shortcode('[map address="'.esc_html( get_the_title() ).'"]');
}
function mymap_shortcodes_init() {
add_shortcode('mymap', 'mymap_shortcode');
}
add_action('init', 'mymap_shortcodes_init');
And then in posts/pages (or even put it directly to template, or create another filter to add that) use shortcode [mymap] that will run [map] shortcode with current page title as parameter.
I am looking for a simple way to add shortcode to a custom widget(Not in custom template) which i have created using my function file in wordpress,so this shortcode can be used to show my custom stuffs..?Any help
WordPress widgets aren’t enabled to manage shortcodes.So there is a simple trick which can
be used here.
Open your function file and write the following code
add_filter(‘widget_text’, ‘do_shortcode’);
More can be found here
if you want to use the shortcode in widget script, you need to add a function like:
echo do_shortcode('[your_shortcode]');
I am using the theme Magazine Pro for the Genesis Framework. I have a plugin that in order for it to be displayed I must add the following in the loop.
<?php wptopc($format="select", $prepend="<div class='toc'>", $append=""); ?>
<?php wptopc_pagination_links($prepend="", $append="</div>"); ?>
There is no single.php file or anything like that. I also don't want to change the loop entirely, just add the above code to it. How can I do this for only single_posts?
So I figured it out. There is a plugin from StudioPress called Genesis Simple Hooks. It allows you to execute shortcode, html and php into various hook elements in the framework.
For my purpose I just added the php code to genesis_before_entry_content
Another solution is to add a custom function to your child themes functions file with one of the genesis hooks that executes within the loop.
Example:
add_action( 'genesis_before_entry', 'hook_after_header' );
function hook_after_header() {
if ( is_single() ) {
wptopc($format="select", $prepend="<div class='toc'>", $append="");
wptopc_pagination_links($prepend="", $append="</div>");
}
}
I want add Prettyphoto to my blog and I prepare filter:
add_filter( 'wp_get_attachment_link', 'sant_prettyadd');
function sant_prettyadd ($content) {
$content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\"",$content,1);
return $content;
}
But where I should looking file function.php ?
When WordPress is integrated into Magento, the functions.php file is not used, which means that any code you add to it won't have any effect on the frontend of your blog.
The integration extension is Magento based and uses Magento templates to display your blog. You probably want to add the preg_replace function call to the post view template. This can be found at the following location:
app/design/frontend/base/default/template/wordpress/post/view.phtml
To make changes to this file, first copy it to your custom theme and edit it there. Look for the following line:
<?php echo $post->getPostContent() ?>
This is the code that retrieves the post content. You can use the preg_replace call here to achieve what you're trying to do.
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..