My theme uses custom code to display content instead of WordPress. What can I do?
It's another take on the dreaded theme lock-in effect, but with some coding knowledge you can overcome any obstacle the theme throws at you. We can insert the AOA shortcode around the theme's custom code, but you should first create a child theme so any changes made won't be lost when the theme is updated.
Unfortunately, each theme is different, so it is impossible to show a one-size fits all solution.
Example #1 - VideoTube
VideoTube theme takes the custom video field and just echoes it to the screen, bypassing WordPress, so AoA cannot hook in. Thankfully they do use a custom filter, so we can hook into that with this Code Snippets and use the AoA shortcode:
add_filter( 'videotube_player', 'aoa_videotube_player');
function aoa_videotube_player( $video ) {
return do_shortcode('[aoa id="0"]' . $video . '[/aoa]');
}
Note: VideoTube uses the CSS trick to make embedded content responsive, so add this custom CSS code in the AOA Main Settings:
.player .aoa_wrap { padding-bottom: 56.25%; }
Example #2 - deTube
deTube theme takes the custom video field and just echoes it to the screen, bypassing WordPress, so AoA cannot hook in. Thankfully they do use a custom filter, so we can hook into that with this Code Snippets and use the AoA shortcode:
add_filter( 'dp_video_filter', 'aoa_dp_video_filter' );
function aoa_dp_video_filter( $video ) {
return do_shortcode('[aoa id="0"]' . $video . '[/aoa]');
}
Example #3 - Herald
Herald theme takes the custom video field and just echoes it to the screen, bypassing WordPress, so AoA cannot hook in. Thankfully they do use a custom filter, so we can hook into that with this Code Snippets and use the AoA shortcode:
add_filter( 'hybrid_media_grabber_media', 'aoa_hybrid_media_grabber_media' );
function aoa_hybrid_media_grabber_media( $video ) {
return do_shortcode('[aoa id="0"]' . $video . '[/aoa]');
}
Example #4 - Dooplay
Dooplay theme takes the custom video field and just echoes it to the screen, bypassing WordPress, so AoA cannot hook in. Thankfully they do use a custom filter, so we can hook into that with this Code Snippets and use the AoA shortcode:
add_filter( 'doo_player_ajax', 'aoa_doo_video_filter' );
function aoa_doo_video_filter( $video ) {
return do_shortcode('[aoa id="0"]' . $video . '[/aoa]');
}
Dooplay uses a CSS trick to make the video responsive, so be sure to add this custom CSS code in AoA Main Settings:
.pframe .aoa_wrap {
padding-bottom: 56.25%;
}
Example #5 - True Mag
This example is specific to the theme True Mag, which uses *cough* over 900 lines of custom code to show a single post. Luckily, there is one block of code they use to insert a sociallocker shortcode, so we're going to piggy back on that. These changes will allow you to set a custom meta field 'aoa_id' for each post to specify which ad to show, with the default being 0 (a random ad) if not set. If 'aoa_id' is set to < 0 then no ad will be shown.
Original True Mag theme file single-inbox.php, lines ~381 - 400, and header-single-video.php, lines ~440-459
<?php
//social locker
$player_html=ob_get_contents();
ob_end_clean();
//for new shortcode
ob_start();
if($social_locker || $video_ads=='on' || $video_ads_id !== ''){
if(class_exists('video_ads') && ($video_ads=='on' && $video_ads_id !== '' )){
if($video_ads_id=='0'){$video_ads_id='';}
$player_html = '[advs id="'.$video_ads_id.'"]'.$player_html.'[/advs]';
}
if($social_locker){
$id_text = tm_get_social_locker($social_locker);
$player_html = '[sociallocker '.$id_text.']'.$player_html.'[/sociallocker]';
}
echo do_shortcode($player_html);
}else{
echo $player_html;
}
New child theme file single-inbox.php, lines ~381 - 400, and header-single-video.php, lines ~440-459.
<?php
//social locker
$player_html=ob_get_contents();
ob_end_clean();
#AOA change
$aoa_id = get_post_meta( $post->ID, 'aoa_id', true );
if (empty($aoa_id)) $aoa_id = 0;
if ($aoa_id > 0) $player_html = '[aoa id="' . $aoa_id . '"]' . $player_html . '[/aoa]';
//for new shortcode
ob_start();
if($social_locker || $video_ads=='on' || $video_ads_id !== ''){
if(class_exists('video_ads') && ($video_ads=='on' && $video_ads_id !== '' )){
if($video_ads_id=='0'){$video_ads_id='';}
$player_html = '[advs id="'.$video_ads_id.'"]'.$player_html.'[/advs]';
}
if($social_locker){
$id_text = tm_get_social_locker($social_locker);
$player_html = '[sociallocker '.$id_text.']'.$player_html.'[/sociallocker]';
}
echo do_shortcode($player_html);
}else{
echo do_shortcode($player_html); #AOA change
}
I only added/changed the two sections with the # AOA change comment.
Example #6 - Newspaper
This example is specific to the theme Newspaper, which uses the plugin TD Composer to bypass WordPress and display content. You will have to edit their plugin code to get it to work properly with AoA.
In plugin file /td-composer/legacy/common/wp_booster/td_video_support.php, About line 179, the final line of function render_video, change:
return $buffy;
to
return apply_filters( 'the_content', $buffy );
This will connect the content through the WordPress content filter, allowing AoA to work on it.
Note: if you update their plugin your change is overwritten so you'll need to repeat the above every time you update td composer. This is assuming they don't fix their plugin.
Example #7 - Any theme that echoes video code from a custom meta field
Unfortunately there are a number of themes that simply echo video embed code from a custom meta field directly to the screen. This method bypasses WordPress filters so AoA is unable to hook in. These custom coded themes do not play well with others and is the most common reason for support requests, especially because it seems the problem is AoA 'does not work'. The real problem is the custom theme code does not follow standard WordPress practices.
However, if we know the name of the theme's custom meta field, we can use the following custom code with the Code Snippets plugin to force WordPress to wrap and process the meta data with an AoA shortcode. Be sure to check the lines with the comment // USER to match your situation.
add_filter( 'get_post_metadata', 'aoa_custom_meta', 99, 4 );
function aoa_custom_meta( $value, $postID, $meta_key, $single ) {
$custom_meta_key = 'embed_code'; // USER change to match theme custom key for the video code
// are we on a single post page and trying to get video code meta data?
if ( is_single() && $meta_key === $custom_meta_key ) {
// use direct wpdb call to get meta_key value to avoid loop
global $wpdb;
$meta_data = $wpdb->get_var( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $postID AND meta_key = '".$meta_key."'" );
// is AoA is installed and active?
if ( $meta_data && class_exists( 'Ad_Overlay_Anything' ) ) {
$aoa = new Ad_Overlay_Anything();
// wrap the meta_data value with aoa shortcode for a random ad
// USER change id if you want specific ads
$meta_data = '[aoa id="0"]' . $meta_data . '[/aoa]';
// resolve the shortcode
$aoa_meta = $aoa->aoa_auto_overlay( $meta_data ); // auto overlay elements defined in Main Settings
// return the video wrapped with ad code
return $aoa_meta;
}
}
// otherwise return default meta value
return $value;
}