We provide the code snippets and content on this page without any guarantee or support. In most cases, these pages are created on requests or based on individual solutions sent to us by other users. After it was published, we are only reviewing the code and content when we are made aware of an issue. Please let us know if you find one.
Please only use the codes if you understand them and know how to add custom code to your WordPress site.
Ads in Advanced Ads are based on WordPress custom post types. They are disabled to output public URLs.
If you have a good reason to make the ads public on dedicated URLs, then you can use the advanced-ads-post-type-params
hook.
The following code snippet would make ads available under example.com/advanced_ads/[AD_SLUG]/
.
/**
* Allow to query an ad through a public URL like example.com/advanced_ads/AD_SLUG
* Re-save Settings > Permalinks to refresh the permalinks cache after adding the code
*
* For fine-tuning the behavior see https://developer.wordpress.org/reference/functions/register_post_type/
*/
add_filter( 'advanced-ads-post-type-params', function( $post_type_params ) {
$post_type_params['public'] = true;
$post_type_params['rewrite'] = true;
$post_type_params['query_var'] = true;
return $post_type_params;
} );
Code language: PHP (php)
Don’t forget to flush the permalink cache by re-saving Settings > Permalinks.
A public ad URL would use your WordPress theme to output the ad’s content. You could create a custom template file if you only want to load the ad content.