Wordpress - Rev Slider not replacing shortcode - php

So, Basically I have a Revolutionary Slider plugin installed and created one slider. I added the shortcode :
[rev_slider alias="home-original"]
on the homepage. But the slider is just not replacing with the shortcode. The shortcode is displaying as it is on the homepage. I also tried the do_shortcode() function in the header.php but the same occurs.
When I tried this
shortcode_exists('rev_slider')
It prints false.
I also tried this
$active_plugins = (array) get_option( 'active_plugins', array() );
And it shows the rev slider is active.
What more should I try?

I use this to manually add shortcode in PHP:
<?php echo do_shortcode( '[rev_slider alias="slideshow"]' ); ?>
Maybe you forgot to use echo

Related

wpbakery elements shortcode implement in php

I have created a shortcode through wpbakery Add Element section. I am trying to apply this shortcode in PHP
Here is the shortcode
[vc_masonry_grid post_type="post" max_items="10" grid_id="vc_gid:1592135090064-3fb6b6dd-7144-2" taxonomies="16"]
Here is shortcode with PHP code which I have applied in PHP file but it's showing nothing.
I got this function from here
https://developer.wordpress.org/reference/functions/do_shortcode/
echo do_shortcode( '[vc_masonry_grid post_type="post" max_items="10" grid_id="vc_gid:1591334217992-a1326795-3e97-8" taxonomies="16"]' );

Is it possible to insert shortcode inside Header menu or top-bar menu in wordpress?

I have made a simple shortcode for my wordpress theme. I'm trying to align it on right-side above the corner of my page. Is it possible to insert shortcode function.php?
I want to place my Short-code in the top-bar (right side above the corner) so that it will work for each pages. Means if i click on any menu then the shortcode should have to work on that menu also.
Actually i'm new in web development. Please suggest me what shall i have to do so it will align where i want and should have work for each module.
You can use wordpress function for that. Please open the file on which you have to place shortcode. Like if you want to place it on header open header.php and add
<?php echo do_shortcode('[your_shortcode]'); ?>
where you want your shortcode content to appear
The best way is to find the top bar menu hook of your theme and then add this code (adapted for your needs) in your function.php child theme :
function my_shotcode_inside_top_bar ( $items, $args ) {
if (is_page() && $args->theme_location == 'secondary') {
$items .= '<li class="my-class">' . do_shortcode( "[my_shortcode]" ) . '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_shotcode_inside_top_bar', 10, 2 );
is_page displays the shortcode in pages only but you can choose another condition or no condition at all.
secondary is the hook and it depends on your theme. You can normally find it in your theme header.php file.
A menu location selector should be added - that way some themes support multiple menus, and some are called "top" or custom added.
The shortcode could then contain a call to whatever a menu position is:
EG: [myshortcode menu="secondary"]
Didn't have enough points to add this as a comment.

do_shortcode breaks formatting

Has anyone encountered this problem before? Directly calling the shortcode from WordPress and calling the shortcode via functions.php yields different results.
Refer to this
Image 1 has decent design since it was invoked directly from WordPress UI while Image 2 somehow messed up the design because it was invoked from php (functions.php).
Additional info:
Current theme is DIVI
Shortcode/Plugin used is TableMaster
To add further information, I have this line of shortcode in WordPress (as seen on image 2).
[get_blogs_sc]
And on my functions.php, I have this function,
function GetActiveBlogs($i)
{
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (preg_match('/sites/',$actual_link))
{
$user_id = get_current_user_id();
if ($user_id > 0)
{
echo do_shortcode('[tablemaster buttons="true" datatables="true" class="black-header-gray-alternate-rows" sql="some select where user_id = '.user_id.'"]', true);
}
}
}
add_shortcode('get_blogs_sc', 'GetActiveBlogs');
But when I use the shortcode directly from WordPress:
[tablemaster buttons="true" datatables="true" class="black-header-gray-alternate-rows" sql="some select where user_id = 14]
the display on my page looks good (as seen on image 1)
My objective on putting the shortcode in php-layer is for me to be able to capture the logged-in user from WordPress.
Thanks.
it's hard to diagnose what the issue is only from images ! without what the code really says.
but let's know what difference between do_shortcode and add_shortcode
do_shortcode( string $content, bool $ignore_html = false )
Search content for shortcodes and filter shortcodes through their hooks.
it return (string) Content with shortcodes filtered out.
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '' );
for more information check link
while add_shortcode Adds a hook for a shortcode tag.
<?php add_shortcode( $tag , $func ); ?>
$tag
(string) (required) Shortcode tag to be searched in post content
Default: None
$func
(callable) (required) Hook to run when shortcode is found
Default: None
it return nothing but when you write shortcode tag in post area it apply the function of shortcode for more information check Link

How to use shortcodes inside metaboxes in WordPress?

I've created a custom metabox using this example. When the admin-user enters a shortcode in my metabox, the shortcode displays on my front-end as plain text such as:
[menu]
How can I make sure WordPress parses the shortcode so an actual menu is outputted?
I'm using this in my page.php template to display the contents of my custom metabox:
echo get_post_meta( get_the_ID(), '_my_custom_meta_value_key', true );
You can simply use do_shortcode provided by WordPress. This can be used to manually search through the given string for shortcodes.
According to docs for do_shortcode:
Searches content for shortcodes and filters shortcodes through their hooks.
This is how you can do it:
$shortcode = get_post_meta( get_the_ID(), '_my_custom_meta_value_key', true );
echo do_shortcode($shortcode);

short code not working in wordpress text editor

I wanted to add shortcode from the text editor of wordpress post.I have added following short code in the post of wordpress:
<img alt="" src="[template_url]/images/ic_sol_1a.png" />
Here [template_url] is the shortcode i wanted to use it was not working. when i see it in the post page it render the text not the short code response. Somewhere i saw a solutions like adding following line to functions.php of theme:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
But still after adding these lines i am unable to make shortcode work. What could be the possible reason?
my shortcode function is like this:
function my_template_url() {
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
You will need to use the get_bloginfo() to return the value as in your example and make sure to use the_content() to print the value to the page. If you use one of the API methods such as get_the_content() then the do_shortcode filter is not run. If you want to apply it use the following:
function my_template_url() {
// This will echo the 'template_url'
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
$shortcoded = apply_filters( 'the_content', get_the_content() );
You do not need the add_filter() lines.
After lots of headache and with the help of #doublesharp and #Nathan Dawson comments/answers we figured out Problem was inside single.php file of theme we were getting the content of post using get_the_content function. By changing it to the_content() function sortcodes start working. Please note that shortcode will not work in the visual editor of WordPress post on admin site but when you see the post actually in the browser by going to that post you can see it working.

Categories