Hi, you can do that by adding the code below in your theme functions.php file, but note that if you allow users to post ads using [adverts_add] shortcode this can be potentially dangerous as users will be able to run any shortcode in the Ad content.
add_filter( "adverts_the_content", "do_shortcode" );
Hi,
thank you for the reply but this is not solving my problem
after adding the filter to my function.php file, nothing changes.. it still cannot convert my theme shortcode 🙁
i also tried
add_filter( "adverts", "do_shortcode" );
but no luck
Hi, hmm before pasting the code snippet here i tested it on my dev site with the [gallery] shortcode and it seems to be working fine, can you check if it works for you with the [gallery] shortcode (or any other default WP shortcode)?
One other thing i noticed is that you have a custom view for the Ad details page, what code are you using there to display the description?
hi,
i tried to add in the wpadverts/template/single.php
<?php echo do_shortcode('[gallery]'); ?>
and
<?php echo do_shortcode('[gallery id="2"]'); ?>
and nothing is displayed. I mean, i see “nothing” on the frontend page
If i add:
<?php echo do_shortcode('[app_331441694]'); ?>
i just see [app_331441694] on the frontend –> an “echo” of the shortcode, without the “conversion”
If i add:
<?php do_shortcode('[app_331441694]'); ?>
(without the echo) i see “nothing” on the front end.
the [app_id] shortcode is registered in mytheme/inc/shorcodes.php and it works fine if i use it in a post or in a page so it’s pretty strange that your custom_post_type doesn’t display it after the addition of “add_filter( “adverts_the_content”, “do_shortcode” );” in functions.php
the problem is that i really need it to work for the idea i’m going to develop using your plugin 🙁
One other thing i noticed is that you have a custom view for the Ad details page, what code are you using there to display the description?
yes i’ve customized the view.. i also purchased “wpadverts custom fields” so to show the description i’m simply using
<?php echo get_post_meta($post_id, 'app_description', true); ?>
BTW the [app_id] shortcode is not inside the description. it is inside the wpadverts/template/single.php file
please help me
-
This reply was modified 6 years, 1 month ago by fabiano1987.
The line add_filter( "adverts_the_content", "do_shortcode" );
you only need to display the shortcode inside the Description field if you are pasting the PHP code in the templates it should work like when pasting in any other file.
If you will use the code
<?php do_shortcode('[app_331441694]'); ?>
in the theme templates (for example page.php or single.php file) will it work?
If it will then you can try creating in your current theme folder file named single-advert.php and copy to it content from single.php or page.php file then add the shortcode there, it should allow you to have the shortcode on Ad details pages.
BTW. usually (but not always) you should use the do_shortcode function as
<?php echo do_shortcode('[app_331441694]'); ?>
not
<?php do_shortcode('[app_331441694]'); ?>
because the shortcodes should return the content not display it.
i made some searches and i’ve understand that:
1) my shortcodes can be used only inside “the_content”
2) to use a shortcode “outside” the_content, i need to define it in functions.php using “add_shortcode”
What now..
– Here is the_content that i use to show the shortcode inside the_content:
add_action('the_content', 'get_app_id_shortcode18');
function get_app_id_shortcode18( $content ) {
if ( !preg_match_all( '/\[appscr_([0-9]*)\]/im', $content, $matches ) )
return $content;
if ( isset( $matches[1] ) ){
foreach ($matches[0] as $key => $shortcode) {
$app = get_app_info($matches[1][$key]);
if ( $app ){
global $post;
if($post!=NULL)
$post->app = $app;
$device = 'iphonescreens';
$screens = $app->screenshotUrls;
if ( !count($screens) ) {
$screens = $app->ipadScreenshotUrls;
$device = 'ipadscreens';
}
// Qui restituisco le info sull'app
$html = '<ul class="lightGallery '.$device.'">';
foreach ( $screens as $pic ) {
$html.= '<li data-mfp-src="'. get_high_res($pic) .'"><a href="'. get_high_res($pic) .'" title=""><img src="'. img_resize(get_high_res($pic),0,300) .'" alt=""></a></li>';
}
$html.= '</ul>';
/*
echo '<pre>';
var_dump($app);
echo '</pre>';
*/
// Qui effettuo la sostituzione
$content = str_replace($shortcode, $html, $content);
} else {
$content = str_replace($shortcode, 'App ID errato', $content);
}
}
}
return $content;
}
What i have to add in my functions.php to define a new “add_shortcode” instead of “add_action”?
-
This reply was modified 6 years, 1 month ago by fabiano1987.
ok, a friend helped me and now everything is working.
i would like to share the code to help someone else in future.
that’s the final code to add in functions.php to have the shortcode to work:
add_shortcode('appscr', 'nome_funzione_fabiano_1');
function nome_funzione_fabiano_1( $atts, $content = null ) {
// Attributes
$atts = shortcode_atts(
array(
'appscr_id' => '',
),
$atts
);
$app = get_app_info($atts['appscr_id']);
if ( $app ){
$device = 'iphonescreens';
$screens = $app->screenshotUrls;
if ( !count($screens) ) {
$screens = $app->ipadScreenshotUrls;
$device = 'ipadscreens';
}
// Qui restituisco le info sull'app
$html = '<ul class="lightGallery '.$device.'">';
foreach ( $screens as $pic ) {
$html.= '<li data-mfp-src="'. get_high_res($pic) .'"><a href="'. get_high_res($pic) .'" title=""><img src="'. img_resize(get_high_res($pic),0,300) .'" alt=""></a></li>';
}
$html.= '</ul>';
/*
echo '<pre>';
var_dump($app);
echo '</pre>';
*/
// Qui effettuo la sostituzione
return $html;
} else {
return 'App ID errato';
}
}
// To use: echo do_shortcode('[appscr appscr_id="331441694"]');
i will close the topic so.
Thank you Greg, to be interested in my problem
-
This reply was modified 6 years, 1 month ago by fabiano1987.